laravel中的资源(resource)路由的使用方法

laravel框架中的路由:

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
Route::match(['get', 'post'], $uri,$callback);
Route::any($uri, $callback);
Route::redirect('/here', '/there', 301);
Route::view('/welcome', 'welcome');                                                                                         Route::resource("/",'IndexController');

刚开始学习laravel框架的时候,只看到有resource路由,但是不知道该怎么用,研究了好久才明白是怎么回事。

首先,我用的是laravel5.5的框架,先在web.php中编写好路由,如:

Route::group(['prefix'=>'admin','namespace'=>'Admin'],function(){
	Route::resource("/",'IndexController');
});

这段代码其实很好理解。

prefix指的是访问的前缀,namespace则是访问的公共命名空间。

resource('域名/admin/',访问的控制器)  控制器中的方法

 

方法路径动作路由名称
GET/photosindexphotos.index
GET/photos/createcreatephotos.create
POST/photosstorephotos.store
GET/photos/{photo}showphotos.show
GET/photos/{photo}/editeditphotos.edit
PUT/PATCH/photos/{photo}updatephotos.update
DELETE/photos/{photo}destroyphotos.destroy

当输入的链接地址为:域名/admin/时,默认访问的是indexController中的index方法,而post提交的数据默认的是store方法

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值