laravel基础课程---5、路由复习(路由作用)
一、总结
一句话总结:
有利于百度收录,及SEO优化
1、路由书写 (D:laravelyzmeduyzm2
outesweb.php)?
Route::get('/',function(){
Route::get('/',function(){
echo "云知梦";
});
Route::get('admin',function(){
return view();
});
Route::get('admin/user',"UserController@index");
2、路由类型?
六种
Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
3、CSRF保护?
{{csrf_field}}
4、模拟PUT请求、delete请求?
{{csrf_field}}
input type="hidden" name="_method" value="put"
5、路由带参数?
大括号:Route::get("goods_info/{id}",'IndexController@index')
Route::get("goods_info/{id}",function($id){
echo "$id";
});
Route::get("goods_info/{id}",'IndexController@index')
6、设置默认值?
问号:Route::get("goods_info/{id?}",function($id='默认值'){
Route::get("goods_info/{id?}",function($id='默认值'){
echo "$id";
});
7、命名路由?
Route::get('/','IndexController@index')->name('abc');
8、路由组?
命名空间,前缀,中间件:Route::group(['namespace'=>'','prefix'=>'','middleware'=>''],function(){
Route::group(['namespace'=>'','prefix'=>'','middleware'=>''],function(){
});
9、资源路由?
Route::recourse('admin/user','UserController');
二、内容在总结中