本文實例講述了Laravel框架路由管理。分享給大家供大家參考,具體如下:
路由中輸出視圖
Route::get('/', function () { return view('welcome'); });
get路由請求
Route::get('get',function(){ return 'get路由請求'; });
post路由請求
Route::post('post',function(){ return 'post請求'; });
多路由請求
Route::match(['get','post'],'match',function(){ return '多路由請求'; });
任意路由請求
Route::any('any',function(){ return '任意路由請求'; });
路由參數(shù)
Route::get('user/{id}',function($id){ return 'user-id-'.$id; });
路由參數(shù)默認值
Route::get('user/{name?}',function($name = 'yxh'){ return 'user-name-'.$name; });
路由參數(shù)的正則驗證
Route::get('user/{id}/{name?}',function($id,$name = 'yxh'){ return 'user-id-'.$id.'-name-'.$name; })->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']);
路由別名
Route::get('user/member-center',['as'=>'center',function(){ return route('center'); }]);
路由群組
Route::group(['prefix'=>'member'],function(){ //路由別名 Route::get('user/member-center',['as'=>'center',function(){ return route('center'); }]); //任意路由請求 Route::any('any',function(){ return '任意路由請求'; }); });
路由中輸出視圖
Route::get('view',function(){ return view('welcome'); });
關(guān)聯(lián)控制器
Route::get('member/info','MemberController@info'); Route::get('test','UserController@test'); Route::get('query','UserController@query'); Route::get('orm','UserController@orm'); Route::get('section1',['uses'=>'UserController@section1']); Route::get('url',['as'=>'url','uses'=>'UserController@urlTest']);
更多關(guān)于Laravel相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門與進階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于Laravel框架的PHP程序設(shè)計有所幫助。
標(biāo)簽:遼陽 十堰 梅河口 甘肅 韶關(guān) 九江 昭通 涼山
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Laravel框架路由管理簡單示例》,本文關(guān)鍵詞 Laravel,框架,路由,管理,簡單,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。