Laravel routes RESTful resource Controller Route: resource

Source: Internet
Author: User
In routes. php defines a RESTful {code ...} in ComController. php defines the following method {code ...} $ id will report an error. Is there any good way to define a route corresponding to the method under a controller that no longer needs to be defined on the route? {generation... in routes. php defines a RESTful

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

InComController.php

The following method is defined in

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

$idAn error is reported.

Is there any good way to define a route corresponding to a controller?
The following method of the controller does not need to be defined on the route.

Route::controllers([    'com' => 'ComController',]);

How to use this route$idWhat about

RouteRESTfulMethod andcontrollersWhat is the difference?

Please give me some advice.

Reply content:

In routes. php, a RESTful

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

InComController.php

The following method is defined in

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

$idAn error is reported.

Is there any good way to define a route corresponding to a controller?
The following method of the controller does not need to be defined on the route.

Route::controllers([    'com' => 'ComController',]);

How to use this route$idWhat about

RouteRESTfulMethod andcontrollersWhat is the difference?

Please give me some advice.

Your need should be:
Http://laravel.com/docs/5.0/controllers#implicit-controllers

Routes. php

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

UserController. php

php// GET http://domain/users/indexpublic function getIndex() {}// POST http://domain/users/profile/3public function postProfile($id) {}// DELETE http://domain/users/user/3public function deleteUser($id) {}

Verb path behavior route name
GET/photo index photo. index
GET/photo/create photo. create
POST/photo save photo. store
GET/photo/{photo} shows photo. show
GET/photo/{photo}/edit photo. edit
PUT/PATCH/photo/{photo} update photo. update
DELETE/photo/{photo} DELETE photo. destroy
You have read the document, and it has set a good path for you.
For example, index
Restfull should be: http: // {domain}/photo, instead of: http: // {domain}/photo/index

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.