首页 > laravel 路由 RESTful 资源控制器 Route::resource

laravel 路由 RESTful 资源控制器 Route::resource

在 routes.php 定义了 一个 RESTful

Route::resource('com','ComController');

ComController.php

里面 定义了如下方法

    public function index()
    {
        return "index";
    }

    public function show()
    {
        return "show";
    }

    public function edit($id)
    {
        return "edit".$id;
    }

    public function del($id)
    {
        return "del".$id;
    }

$id 都会报错

有什么好的方法 可以 定义好一个路由对应一个控制器
控制器下面的方法 不用再路由上定义呢

Route::controllers([

    'com' => 'ComController',
]);

用此路由 怎么传 $id

路由的 RESTful 方法 和 controllers 有什么区别呢

求大神指点一下啊


动词 路径 行为 路由名称
GET /photo 索引 photo.index
GET /photo/create 创建 photo.create
POST /photo 保存 photo.store
GET /photo/{photo} 显示 photo.show
GET /photo/{photo}/edit 编辑 photo.edit
PUT/PATCH /photo/{photo} 更新 photo.update
DELETE /photo/{photo} 删除 photo.destroy
你注意看文档,它已经给你规定好了路劲
比如index
restfull 应该是:http://{domain}/photo,而不是:http://{domain}/photo/index


你的需求应该是这个:
http://laravel.com/docs/5.0/controllers#implicit-controllers

routes.php

phpRoute::controller('users', 'UserController');

UserController.php

php// GET http://domain/users/index
public function getIndex() {}
// POST http://domain/users/profile/3
public function postProfile($id) {}
// DELETE http://domain/users/user/3
public function deleteUser($id) {}
【热门文章】
【热门文章】