安装Laravel-ide-helper
composer.json中require字段添加
"barryvdh/laravel-ide-helper":"dev-master"
配置好后在文件的根目录运行 composer update命令,
安装完成后添加代码到laravel/config/app.php文件providers中追加行
BarryvdhLaravelIdeHelperIdeHelperServiceProvider::class,
最后项目根目录执行:
php artisan ide-helper:generate
之后这个命令应该会生成一个叫 “_ide_helper.php” 的文件,安装完毕。如果不生效尝试重启编辑器。
路由
Route::get('/', 'StaticPagesController@home')->name('home'); Route::get('/help', 'StaticPagesController@help')->name('help'); Route::get('/about', 'StaticPagesController@about')->name('about'); Route::get('signup', 'UsersController@create')->name('signup'); Route::resource('users', 'UsersController'); //以上代码等同于 Route::get('/users', 'UsersController@index')->name('users.index'); Route::get('/users/create', 'UsersController@create')->name('users.create'); Route::get('/users/{user}', 'UsersController@show')->name('users.show'); Route::post('/users', 'UsersController@store')->name('users.store'); Route::get('/users/{user}/edit', 'UsersController@edit')->name('users.edit'); Route::patch('/users/{user}', 'UsersController@update')->name('users.update'); Route::delete('/users/{user}', 'UsersController@destroy')->name('users.destroy');
两种写法,推荐方法二
//路由分组写法一 Route::group(['prefix'=>'api'],function(){ Route::get('index','TaskController@index'); Route::get('task','TaskController@task'); }); //路由分组写法二 Route::prefix('api')->group(function(){ Route::get('index','TaskController@index'); Route::get('task','TaskController@task'); });
Migration
//创建控制器 php artisan make:controller AdminArticleController //创建模型并生成migrate迁移文件 php artisan make:model Models/Article -m //创建播种器并创建规则 php artisan make:seeder ArticleTableSeeder.php //运行填充器 php artisan db:seed --class=ArticleTableSeeder