-
Controller 控制器
// 創(chuàng)建一個控制器 php artisan make:controller XXXController // 創(chuàng)建Rest風格資源控制器 php artisan make:controller PhotoController --resource // 指定創(chuàng)建位置 在app目錄下創(chuàng)建TestController php artisan make:controller App\TestController?
-
Model
// 指定路徑創(chuàng)建 php artisan make:Model App\\Models\\User(linux or macOs 加上轉義符)?
-
Migration 數(shù)據(jù)遷移
// 數(shù)據(jù)遷移 php artisan migrate // 創(chuàng)建遷移 php artisan make:migration create_users_table // 指定路徑 php artisan make:migration --path=app\providers create_users_table // 一次性創(chuàng)建 // 下述命令會做兩件事情: // 在 app 目錄下創(chuàng)建模型類 App\Post // 創(chuàng)建用于創(chuàng)建 posts 表的遷移,該遷移文件位于 database/migrations 目錄下。 php artisan make:model --migration Post?
-
Seeder 數(shù)據(jù)填充
// 創(chuàng)建要填充的數(shù)據(jù)類 php artisan make:seeder UsersTableSeeder // 數(shù)據(jù)填充(全部表) php artisan db:seed // 指定要填充的表 php artisan db:seed --class=UsersTableSeeder?
-
Middleware 中間件
php artisan make:middleware XXX?
-
Route 路由
// 查看所有路由 php artisan route:list?
-
Request請求,主要用于表單驗證
php artisan make:request TagCreateRequest創(chuàng)建的類存放在 app/Http/Requests 目錄下
<?php namespace App\Http\Requests; use App\Http\Requests\Request; class TagCreateRequest extends Request { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'tag' => 'required|unique:tags,tag', 'title' => 'required', 'subtitle' => 'required', 'layout' => 'required', ]; } }使用時只需在對應的Controller方法里引入
// 注意這里使用的是TagCreateRequest public function store(TagCreateRequest $request) { $tag = new Tag(); foreach (array_keys($this->fields) as $field) { $tag->$field = $request->get($field); } $tag->save(); return redirect('/admin/tag') ->withSuccess("The tag '$tag->tag' was created."); }?
-
創(chuàng)建artisan命令行(laravel5.*版本)
// 以下命令生成文件 app/Console/Commands/TopicMakeExcerptCommand.php php artisan make:console TopicMakeExcerptCommand --command=topics:excerpt123//在 app/Console/Kernel.php 文件里面, 添加以下 protected $commands = [ \App\Console\Commands\TopicMakeExcerptCommand::class, ]; //激活artisan命令行。12345 //在生成的TopicMakeExcerptCommand.php 文件, 修改以下區(qū)域 <?php namespace App\Console\Commands; use Illuminate\Console\Command; class TopicMakeExcerptCommand extends Command { /** * 1. 這里是命令行調用的名字, 如這里的: `topics:excerpt`, * 命令行調用的時候就是 `php artisan topics:excerpt` * * @var string */ protected $signature = 'topics:excerpt'; /** * 2. 這里填寫命令行的描述, 當執(zhí)行 `php artisan` 時 * 可以看得見. * * @var string */ protected $description = '這里修改為命令行的描述'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * 3. 這里是放要執(zhí)行的代碼, 如在我這個例子里面, * 生成摘要, 并保持. * * @return mixed */ public function handle() { $topics = Topic::all(); $transfer_count = 0; foreach ($topics as $topic) { if (empty($topic->excerpt)) { $topic->excerpt = Topic::makeExcerpt($topic->body); $topic->save(); $transfer_count++; } } $this->info("Transfer old data count: " . $transfer_count); $this->info("It's Done, have a good day."); } }// 命令行調用 php artisan topics:excerpt
Laravel Artisan常用命令
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
相關閱讀更多精彩內容
- Spring Cloud為開發(fā)人員提供了快速構建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現(xiàn),斷路器,智...
- 校園失物招領平臺開發(fā) ——基于laravel框架構建最小內容管理系統(tǒng) 摘要 ? 針對目前大學校園人口密度大、人群活...