(一) 路由

基本路由

Route::get('/',function(){

     return view('welcome');

})

Route::post('/',function(){

return view('welcome');

})

Route::put('/',function(){

return view('welcome');

})

Route::delete('/',function(){

return view('welcome');

})

Route::options('/',function(){

return view('welcome');

})

Route::patch('/',function(){

return view('welcome');

})

Route::any('/',function(){

return view('welcome');

})

匹配方式

Route::match(['get','post'],'/',function(){

return view('welcome');

})

路由参数

一个参数

//url中的参数和function()中的参数名字可以不同

Route::get('user/{id}',function($id){

return 'User.'.$id;

}

二个参数

Route::get('user/{id}/post/{e}',function($id,$e){

return 'User.'.$id.$e;

}

url / 换成 _

Route::get('user_{id}',function($id){

return 'User.'.$id;

}

可选参数

对于有两个路由参数一般最后一个可以使用可选参数

Route::get('user/{id?}',function($id='www'){

return 'User.'.$id;

})

参数规则(正则表达式)

Route::get('user/{id}/post/{e}',function($id,$e){

return 'User.'.$id.$e;

})->where(['id' =>'[0-9]+','e'=>'[a-zA-Z]+']);

路由别名

Route::get('/one',[ 'as' =>'one' ,function(){

return 'User.'

]});

route('one');

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容