Nghĩa Của Từ Artisan Là Gì ? (Từ Điển Anh Nghĩa Của Từ Artisan, Từ Artisan Là Gì

Related Articles

Khi mới làm quen với framework Laravel, tôi cũng như bạn rất quá bất ngờ khi biết có một công cụ dòng lệnh. Tôi vốn xuất thân từ một quản trị mạng, nói đến những công cụ dòng lệnh ( command line hay console ) là nghĩ ngay đến những thông số kỹ thuật thiết bị mạng, nhưng giờ đây khi làm lập trình thì Laravel Artisan là cái quái quỉ gì vậy, chẳng lẽ cũng dùng nó để thông số kỹ thuật ?

1. Laravel Artisan là cái gì?

Artisan phiên âm /ärdəzən/ có ý nghĩa là nghệ nhân, là người xử lý một công việc nào đó thủ công một cách cực xuất sắc.

Bạn đang xem: Artisan là gì

Laravel Artisan là một công cụ dòng lệnh được tích hợp sẵn trong các dự án sử dụng Laravel, nó cung cấp rất nhiều các chức năng trợ giúp việc xây dự án, giảm thời gian viết code cũng như tự động hóa một số công việc. Laravel Artisan xứng đáng với cái tên của nó, nó thật sự xuất sắc khi xử lý các công việc mang tính thủ công bằng cách tự động hóa chúng.

Các công việc xử lý cơ sở dữ liệu như migrate, đưa dữ liệu vào database, tạo dữ liệu kiểm thử.Artisan cũng có thể tạo các template là các Class trong lập trình theo các mẫu khác nhau như tạo ra các Model, Controller, Event…Chạy các công cụ ngoài như Tinker, hoặc cho phép người dùng tạo ra các công cụ tùy thích.

Các công việc xử lý cơ sở dữ liệu như migrate, đưa dữ liệu vào database, tạo dữ liệu kiểm thử.Artisan cũng có thể tạo các template là các Class trong lập trình theo các mẫu khác nhau như tạo ra các Model, Controller, Event…Chạy các công cụ ngoài như Tinker, hoặc cho phép người dùng tạo ra các công cụ tùy thích.

Bạn có thể sử dụng câu lệnh php artisan list để xem danh sách các câu lệnh hỗ trợ bởi Artisan:

c : xampp htdocs benh.edu.vn > php artisan listLaravel Framework 5.4.19 Usage : command Options : – h, — help Display this help message – q, — quiet Do not output any message – V, — version Display this application version — ansi Force ANSI output — no-ansi Disable ANSI output – n, — no-interaction Do not ask any interactive question — env The environment the command should run under – v | vv | vvv, — verbose Increase the verbosity of messages : 1 for normal output, 2 for more verbose output and 3 for debugAvailable commands : clear-compiled Remove the compiled class file down Put the application into maintenance mode env Display the current framework environment help Displays help for a command inspire Display an inspiring quote list Lists commands migrate Run the database migrations optimize Optimize the framework for better performance serve Serve the application on the PHP development server tinker Interact with your application up Bring the application out of maintenance mode app app : name Set the application namespace auth auth : clear-resets Flush expired password reset tokens cache cache : clear Flush the application cache cache : forget Remove an item from the cache cache : table Create a migration for the cache database table config config : cache Create a cache file for faster configuration loading config : clear Remove the configuration cache file db db : seed Seed the database with records sự kiện sự kiện : generate Generate the missing events and listeners based on registration key key : generate Set the application key make make : auth Scaffold basic login and registration views and routes make : command Create a new Artisan command make : controller Create a new controller class make : sự kiện Create a new sự kiện class make : job Create a new job class make : listener Create a new sự kiện listener class make : mail Create a new email class make : middleware Create a new middleware class make : migration Create a new migration file make : Mã Sản Phẩm Create a new Eloquent Mã Sản Phẩm class make : notification Create a new notification class make : policy Create a new policy class make : provider Create a new service provider class make : request Create a new form request class make : seeder Create a new seeder class make : test Create a new test class migrate migrate : install Create the migration repository migrate : refresh Reset and re-run all migrations migrate : reset Rollback all database migrations migrate : rollback Rollback the last database migration migrate : status Show the status of each migration notifications notifications : table Create a migration for the notifications table passport passport : client Create a client for issuing access tokens passport : install Run the commands necessary to prepare Passport for use passport : keys Create the encryption keys for API authentication queue queue : failed List all of the failed queue jobs queue : failed-table Create a migration for the failed queue jobs database table queue : flush Flush all of the failed queue jobs queue : forget Delete a failed queue job queue : listen Listen to a given queue queue : restart Restart queue worker daemons after their current job queue : retry Retry a failed queue job queue : table Create a migration for the queue jobs database table queue : work Start processing jobs on the queue as a daemon route route : cache Create a route cache file for faster route registration route : clear Remove the route cache file route : list List all registered routes schedule schedule : run Run the scheduled commands session session : table Create a migration for the session database table storage storage : link Create a symbolic link from ” public / storage ” to ” storage / app / public ” vendor vendor : publish Publish any publishable assets from vendor packages view view : clear Clear all compiled view files Đến đây chắc rằng bạn cũng đã nắm được Laravel Artisan là cái gì và nó được sử dụng như thế nào ? Tuy nhiên còn rất nhiều điều cần nói đến về Artisan, tất cả chúng ta liên tục nhé .

2. Laravel REPL

REPL là gì? REPL viết tắt của Read – Eval – Print Loop, còn được biết đến với tên language shell, đơn giản là một ngôn ngữ cho phép lặp đi lặp lại các việc Đọc dữ liệu, Tính toán dữ liệu và In ra màn hình. Các ứng dụng Laravel trong đó có Tinker là một ngôn ngữ REPL được hỗ trợ bởi PsySH.

Xem thêm: Scoliosis Là Gì – Phục Hồi Chức Năng Cho Trẻ Em Cong Vẹo Cột Sống

PsySH : A runtime developer console, interactive debugger and REPL for PHP. Công cụ dòng lệnh runtime cho thiên nhiên và môi trường tăng trưởng, tương tác khi debug và REPL trong ngôn từ PHP

Laravel Tinker cho phép bạn tương tác với các thực thể trong ứng dụng như Eloquent ORM, job, event… Nó cũng rất tiện cho chúng ta khi muốn kiểm tra một dòng lệnh xem nó hoạt động thế nào, trong rất nhiều bài viết tôi đã sử dụng Laravel Tinker như một công cụ để chạy các dòng lệnh mẫu thay vì phải viết hẳn một ví dụ mẫu. Để chạy Laravel Tinker bạn sử dụng câu lệnh php artisan tinker

3. Câu lệnh Laravel Artisan cho mục đích riêng

3.1 Tạo template cho câu lệnh Artisan

Bạn hoàn toàn có thể tạo ra các câu lệnh Artisan cho các mục đích riêng, các file class PHP cho các câu lệnh này thường được lưu vào thư mục appConsoleCommands. Artisan sẽ tạo ra một template sẵn cho câu lệnh cá nhân bằng lệnh php artisan make:command, nó sẽ tạo ra một file class cho câu lệnh này trong appConsoleCommands. Trong ví dụ sau đây chúng ta sẽ tạo ra một câu lệnh mỗi khi thực hiện nó sẽ tạo ra một hoặc nhiều user thường hoặc user có quyền quản trị cho hệ thống. Đầu tiên tạo ra class UserCommand bằng artisan make:command.

Bạn hoàn toàn có thể tạo ra các câu lệnh Artisan cho các mục đích riêng, các file class PHP cho các câu lệnh này thường được lưu vào thư mục appConsoleCommands. Artisan sẽ tạo ra một template sẵn cho câu lệnh cá nhân bằng lệnh php artisan make:command, nó sẽ tạo ra một file class cho câu lệnh này trong appConsoleCommands. Trong ví dụ sau đây chúng ta sẽ tạo ra một câu lệnh mỗi khi thực hiện nó sẽ tạo ra một hoặc nhiều user thường hoặc user có quyền quản trị cho hệ thống. Đầu tiên tạo ra class UserCommand bằng artisan make:command.

c : xampp htdocs benh.edu.vn > php artisan make : command UserCommandConsole command created successfully. Khi đó bạn sẽ thấy file UserCommand. php trong app Console Commands với nội dung mẫu như sau :

Lớp này là kế thừa lớp Command và có hai thuộc tính bạn cần để ý là $signature và $description, nó sẽ được sử dụng để hiển thị thông tin khi in danh sách câu lệnh bằng php artisan list. Phương thức handle() sẽ được gọi đến khi thực hiện câu lệnh.

Xem thêm: Tổng Hợp Phản Dame Nghĩa Là Gì ? Dame Trong Game Được Hiểu Như Thế Nào

3.2 Định nghĩa các tham số và tùy chọn cho câu lệnh Artisan

Các tham số cho câu lệnh Artisan được định nghĩa trong thuộc tính USD signature. Thuộc tính này được cho phép bạn định nghĩa tên câu lệnh, tham số và những tùy chọn. Các tham số được định nghĩa trong hai dấu ngoặc nhọn { parameter }. Chúng ta cũng hoàn toàn có thể mặc định giá trị bắt đầu cho những tham số.

More on this topic

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Advertismentspot_img

Popular stories