Artisan là một giao diện dòng lệnh (CLI) đi kèm với Laravel PHP framework cung cấp một số lệnh hữu ích để tăng tốc quy trình phát triển.
Các câu lệnh Artisan cơ bản:
php artisan serve
php artisan make:model ModelName
app
của dự án.
php artisan make:model ModelName -m
app
và một file migration trong thư mục database/migrations
.
php artisan make:controller ControllerName
app/Http/Controllers
của dự án.
php artisan make:controller ControllerName --resource
php artisan make:controller ControllerName --model=ModelName
php artisan make:middleware MiddlewareName
app/Http/Middleware
của dự án.
php artisan make:migration create_table_name
database/migrations
của dự án.
php artisan migrate
php artisan migrate:rollback
Hủy bỏ việc thực thi các migration gần nhất, giảm cấu trúc cơ sở dữ liệu về trạng thái trước khi thực hiện migration.
php artisan migrate:reset
php artisan migrate:refresh
php artisan migrate:status
php artisan migrate:fresh
php artisan make:seeder SeederName
database/seeders
của dự án.
php artisan route:list
php artisan route:clear
php artisan optimize
php artisan optimize
.
php artisan optimize:clear
php artisan optimize
. Điều này có thể hữu ích khi bạn muốn tạo lại các cache sau khi thay đổi mã nguồn.
php artisan config:cache
Tạo một bản cache cho tất cả các tệp cấu hình trong thư mục config
, giúp giảm thời gian load cấu hình và cải thiện hiệu suất ứng dụng.
php artisan view:clear
php artisan view:cache
. Điều này thường được thực hiện khi bạn đã thay đổi các tệp view và muốn làm mới các cache của chúng.Tóm tắt các lệnh php artisan cơ bản
# 1. Quản lý ứng dụng
php artisan serve
php artisan down
php artisan up
# 2. Quản lý cơ sở dữ liệu
## Migrations
php artisan make:migration {name}
php artisan migrate
php artisan migrate:rollback
php artisan migrate:reset
php artisan migrate:refresh
php artisan migrate:status
## Seeding
php artisan make:seeder {name}
php artisan db:seed
php artisan db:seed --class={class}
php artisan migrate:fresh --seed
# 3. Quản lý mô hình (Model)
php artisan make:model {name}
php artisan make:model {name} -m
php artisan make:model {name} -c
php artisan make:model {name} -mc
# 4. Quản lý Controller
php artisan make:controller {name}
php artisan make:controller {name} --resource
php artisan make:controller {name} --api
# 5. Quản lý Middleware
php artisan make:middleware {name}
# 6. Quản lý Request
php artisan make:request {name}
# 7. Quản lý Jobs và Queues
php artisan make:job {name}
php artisan queue:work
php artisan queue:retry {id}
php artisan queue:failed
php artisan queue:flush
# 8. Quản lý Events và Listeners
## Events
php artisan make:event {name}
## Listeners
php artisan make:listener {name}
php artisan event:generate
# 9. Quản lý Commands
php artisan make:command {name}
php artisan list
# 10. Cache và Config
## Cache
php artisan cache:clear
php artisan config:cache
php artisan config:clear
php artisan route:cache
php artisan route:clear
php artisan view:clear
# 11. Quản lý Routes
php artisan route:list
php artisan route:cache
php artisan route:clear
# 12. Quản lý Views
php artisan make:component {name}
php artisan view:clear
# 13. Tinker
php artisan tinker
# 14. Testing
php artisan make:test {name}
php artisan test
# 15. Khác
php artisan make:policy {name}
php artisan storage:link
https://tritue.edu.vn/tuecode/tracnghiem30/index.php/baiviet/post/view/id/231?id=231