laravel中路由的代碼實(shí)例介紹

這篇文章給大家介紹的內(nèi)容是關(guān)于laravel中路由的代碼實(shí)例介紹,有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對(duì)你有所幫助。

路由簡(jiǎn)介

請(qǐng)求轉(zhuǎn)化給程序

作用:url和程序之間的映射

請(qǐng)求方式post get put patch delete?

eg:

//get請(qǐng)求 Route::get('basic1',function(){ ????return?'hello?world'; }); //多種請(qǐng)求 //指定請(qǐng)求方式 Route::match(['get','post'],'match',function(){ ????return?'match'; }); //不指定 Route::any('any',function(){ ????return?'any'; }); //路由參數(shù) Route::get('user/{id}',function($id){ ????return?'User-'.$id; }); Route::get('user/{id?}/{name?}',function($id,$name){ ????return?'User-name-'.$name; })->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']); //請(qǐng)求的路由?http://localhost/public/user/1/w
//路由的別名 Route::get('user/member-center',['as'=>'center',function(){ ????return?route('center'); }]); //路由群組 //prefix?前綴 Route::group(['prefix'=>'member'],function(){ ????Route::get('user/center',['as'=>'center',function(){ ????????return?route('center'); ????}]); ????Route::get('user/person',['as'=>'person',function(){ ????????return?route('person'); ????}]); }); //路由中輸出view Route::get('view',?function?()?{ ????return?view('welcome');? });

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊5 分享