欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Laravel资源理由器跟隐式控制的对比及是怎样的吧?- Route::resource vs Route::controller 可以传参数

Laravel资源理由器跟隐式控制的对比及是怎样的吧?- Route::resource vs Route::controller

stackoverflow找到的问题:http://stackoverflow.com/questions/23505875/laravel-routeresource-vs-routecontroller

 

Route::resource('users', 'UsersController');

复制代码
Verb    Path                        Action  Route Name
GET     /users                      index   users.index
GET     /users/create               create  users.create
POST    /users                      store   users.store
GET     /users/{user}               show    users.show
GET     /users/{user}/edit          edit    users.edit
PUT     /users/{user}               update  users.update
DELETE  /users/{user}               destroy users.destroy
复制代码
And you would set up your controller something like this (actions = methods)
复制代码
class UsersController extends BaseController {

    public function index() {}

    public function show($id) {}

    public function store() {}

}
复制代码

You can also choose what actions are included or excluded like this:

复制代码
Route::resource('users', 'UsersController', [
    'only' => ['index', 'show']
]);

Route::resource('monkeys', 'MonkeysController', [
    'except' => ['edit', 'create']
]);
复制代码

https://laravel.com/docs/4.2/controllers#restful-resource-controllers

 

Implicit controller

An Implicit controller is more flexible. You get routed to your controller methods based on the HTTP request type and name. However, you don't have route names defined for you and it will catch all subfolders for the same route.

Route::controller('users', 'UserController');
Would lead you to set up the controller with a sort of RESTful naming scheme:
复制代码
class UserController extends BaseController {

    public function getIndex()
    {
        // GET request to index
    }

    public function getShow($id)
    {
        // get request to 'users/show/{id}'
    }

    public function postStore()
    {
        // POST request to 'users/store'
    }

}
复制代码

 

Implicit Controllers

https://laravel.com/docs/4.2/controllers#implicit-controllers


来自  https://www.cnblogs.com/smallyi/p/6599697.html

普通分类: