Laravel php artisan 自動生成Model+Migrate+Controller 命令大全


php artisan 命令是Laravel框架自帶的命令,方便用戶快速創建、查看對應的模塊參數等。

 

一、常用的命令:

php artisan list                             查看php artisan所有命令

php artisan --help                        查看php artisan的用法

php artisan help admin:make      查看php artisan admin:make的用法

php artisan admin:make --help   查看php artisan admin:make的用法

 

創建控制器
  1. php artisan make:controller OrderController
 
創建Rest風格資源控制器(帶有index、create、store、edit、update、destroy、show方法)
  1. php artisan make:controller OrderController --resource
 
創建模型
  1. php artisan make:model Student
 
創建新建表的遷移和修改表的遷移
  1. php artisan make:migration create_orders_table --create=orders //創建訂單表orders
  2. php artisan make:migration add_tags_to_orders_table --table=orders//給orders表增加tags字段
 
執行遷移
  1. php artisan migrate
 
創建模型的時候同時生成新建表的遷移+控制器+路由
  1. php artisan make:model Order -m -c -r
 
回滾上一次的遷移
  1. php artisan migrate:rollback
 
回滾所有遷移
  1. php artisan migrate:reset
 
創建填充
  1. php artisan make:seeder OrderTableSeeder
 
執行單個填充
  1. php artisan db:seed --class=OrderTableSeeder
 
執行所有填充
  1. php artisan db:seed
 
創建中間件(app/Http/Middleware 下)
  1. php artisan make:middleware Activity
 
創建隊列(數據庫)的表遷移(需要執行遷移才生效)
  1. php artisan queue:table
 
創建隊列類(app/jobs下):
  1. php artisan make:job SendEmail
 
創建請求類(app/Http/Requests下)
  1. php artisan make:request CreateArticleRequest

 

二、通常一個laravel項目的后台管理系統搭建流程,如下

1、下載Laravel框架,安裝Laravel-admin后台管理框架,進行基礎的數據庫連接配置,上傳配置,https/http訪問方式等

2、Linux服務器下面,進入項目的根目錄,可以用php artisan make命令創建模型+數據遷移+控制器。

3、用php artisan admin:make 創建后台的控制器,可以寫腳本批量創建。之后根據業務邏輯,編寫控制器內容。

4、為后台的控制器創建對於的路由,可以寫腳本批量創建。

5、登錄Laravel-admin后台系統,設置對應的菜單。

 

三、Laravel Artisan 命令大全

Available commands:

命令 中文 English
clear-compiled 刪除已編譯的類文件 Remove the compiled class file
down 將應用程序置於維護模式 Put the application into maintenance mode
dump-server 啟動轉儲服務器以收集轉儲信息。 Start the dump server to collect dump information.
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 緩存框架引導程序文件 Cache the framework bootstrap files
preset 為應用程序交換前端腳手架 Swap the front-end scaffolding for the application
serve 在 PHP 開發服務器上提供應用程序 Serve the application on the PHP development server
tinker 與您的應用程序互動 Interact with your application
up 使應用程序退出維護模式 Bring the application out of maintenance mode
 

app

命令 中文 English
app:name 設置應用程序命名空間 Set the application namespace
 

auth

命令 中文 English
auth:clear-resets 刷新過期的密碼重置令牌 Flush expired password reset tokens
 

cache

命令 中文 English
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

命令 中文 English
config:cache 創建緩存文件以加快配置速度 Create a cache file for faster configuration loading
config:clear 刪除配置緩存文件 Remove the configuration cache file
 

db

命令 中文 English
db:seed 填充數據庫 Seed the database with records
 

event

命令 中文 English
event:generate 根據注冊生成缺少的事件和偵聽器 Generate the missing events and listeners based on registration
 

key

命令 中文 English
key:generate 生成應用程序 key Set the application key
 

lang

命令 中文 English
lang:publish 將語言文件發布到資源目錄 publish language files to resources directory.
 

make

命令 中文 English
make:auth --- Scaffold basic login and registration views and routes
make:channel 創建一個新的 channel 類 Create a new channel class
make:command 創建一個新的 Artisan 命令 Create a new Artisan command
make:controller 創建一個新的控制器類 Create a new controller class
make:event --- 創建一個新的 event 類
make:exception 創建一個新的自定義異常類 Create a new custom exception class
make:factory 創建一個新的模型工廠 Create a new model factory
make:job 創建一個新的工作類 Create a new job class
make:listener 創建一個新的事件監聽器類 Create a new event listener class
make:mail 創建一個新的電子郵件類 Create a new email class
make:middleware 創建一個新的中間件類 Create a new middleware class
make:migration 創建一個新的遷移文件 Create a new migration file
make:model 創建一個新的 Eloquent 模型類 Create a new Eloquent model class
make:notification 創建一個新的通知類 Create a new notification class
make:observer 創建一個新的觀察者類 Create a new observer 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:resource 創建一個新資源 Create a new resource
make:rule 創建新的驗證規則 Create a new validation rule
make:scaffold 代碼生成器 — Laravel 5.x Scaffold Generator Create a laralib scaffold
make:seeder 創建一個新的 seeder 類 Create a new seeder class
make:test 創建一個新的測試類 Create a new test class
 

migrate

命令 中文 English
migrate:fresh 刪除所有表並重新運行所有遷移 Drop all tables and re-run all migrations
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

命令 中文 English
notifications:table 為通知表創建遷移 Create a migration for the notifications table
 

optimize

命令 中文 English
optimize:clear 刪除緩存的引導程序文件 Remove the cached bootstrap files
 

package

命令 中文 English
package:discover 重建緩存的包清單 Rebuild the cached package manifest
 

queue

命令 中文 English
queue:failed 列出所有 failed 隊列工作 List all of the failed queue jobs
queue:failed-table 為 failed 隊列工作數據庫表創建遷移 Create a migration for the failed queue jobs database table
queue:flush 刷新所有 failed 隊列工作 Flush all of the failed queue jobs
queue:forget 刪除 failed 隊列工作 Delete a failed queue job
queue:listen 監聽一個給定的隊列 Listen to a given queue
queue:restart 在當前工作之后重新啟動隊列工作器守護程序 Restart queue worker daemons after their current job
queue:retry 重試 failed 隊列作業 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

命令 中文 English
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

命令 中文 English
schedule:run 運行預定的命令 Run the scheduled commands
 

session

命令 中文 English
session:table 為會話數據庫表創建遷移 Create a migration for the session database table
 

storage

命令 中文 English
storage:link 創建從 “公共 / 存儲” 到 “存儲 / 應用 / 公共” 的符號鏈接 Create a symbolic link from "public/storage" to "storage/app/public"
 

vendor

命令 中文 English
vendor:publish 從供應商包中發布任何可發布的資產 Publish any publishable assets from vendor packages
 

view

 

命令 中文 English
view:cache 編譯所有應用程序的 Blade 模板 Compile all of the application's Blade templates
view:clear 清除所有編譯的視圖文件 Clear all compiled view files

 

 

 

 

 

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM