laravel基础课程---5、路由复习(路由作用)

该博客是Laravel基础课程的路由复习内容。介绍了路由的作用,包括利于百度收录和SEO优化。还详细讲解了路由书写、类型、CSRF保护、模拟请求、带参数、设置默认值、命名路由、路由组和资源路由等方面的知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

laravel基础课程---5、路由复习(路由作用)

一、总结

一句话总结:

有利于百度收录,及SEO优化

 

1、路由书写 (D:\laravel\yzmedu\yzm2\routes\web.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');

 

 

二、内容在总结中

 

 

 

 

转载于:https://www.cnblogs.com/Renyi-Fan/p/10834788.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值