入门路由
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
Route::get('/', function () { return view('welcome'); }); Route::get('/test', function () { return view('welcome'); }); /*控制器路由*/ Route::get('userd',[ 'as'=>'profiled', 'uses'=>'Admin\IndexController@index' ]); /*路由命名*/ Route::get('user/', ['as' => 'profile', function () { /*直接输出当前路由的url*/ echo route('profile'); echo "命名路由"; }]); /*一般使用这种方法*/ Route::get('user/test','Admin\IndexController@index')->name('adminTest'); /*===路由分组===*/ /*路由前缀*/ Route::group(['prefix' => 'admin'], function () { Route::get('users','Admin\IndexController@index'); }); /*把相同的命名空间提取出来*/ //Route::group(['prefix' => 'admin','namespace'=>'Admin'], function () { // Route::get('users','IndexController@index'); // Route::get('login','IndexController@login'); //}); /*RESTful 资源控制器*/ Route::resource('article', 'Admin\ArticleController'); //列出所有路由: php artisan route:list /*中间件*/ //创建中间件 php artisan make:middleware TestMiddle Route::group(['middleware'=>'TestMiddle'], function () { Route::get('user','IndexController@index'); Route::get('login','IndexController@login'); }); Route::get('/my','MyController@index'); |
视图相关及分配数据
1 2 3 4 5 6 7 8 9 10 11 |
public function index(){ /*向视图分配数据*/ //return View('my')->with('my','Laravel 6')->with('you','呵呵哒~'); $data = array( 'my'=>'Laravel 6', 'you'=>'呵呵哒~', ); $test = '我是测试数据'; return View('my',$data); return View('my',compact($data,$test)); } |