[Laravel5.1-0.0.4] easy Restful routing and control

Source: Internet
Author: User
[Laravel5.1-0.0.4] easy Restful routing and control

My book: http://www.jianshu.com/users/85c8826ce087/latest_articles
The following uses the CURD operation in the article as an example. This article only covers the basic routing and controller> methods. the specific implementation will be further explained later.

1. create a route
    • In app/Http/routes. php, add:
      Route: resource ('article', 'articlecontroller ');

    • The sub-path contained in the resource route is shown in the following example table;

    2. Controller
    • Create a controller through the terminal
      Php artisan make: controller ArticleController

    • Get the controller app/Http/Controllers/ArticleController

    • If you want to create a folder under app/Http/Controllers and create a controller class in the folder, you can run the following command:
      Php aritsan make: controller Article/ArticleController

    • Controller class example:

     3. (routing ---> controller) Restful reference link example table:
     
    Request method Route address Corresponding controller method Corresponding route name Current role
    GET /Article Index () Route ('article. index ') Show article list
    GET /Article/ Create () Route ('article. create ') Document creation page
    POST /Article Store (Request $ request) Route ('article. store ') Document Storage Operations
    GET /Article/{id} Show ($ id) Route ('article. index ') Show article details
    GET /Article/{id}/edit Edit ($ id) Route ('article. edit ') Article editing page
    PUT/PATCH /Article/{id }/ Update (Request $ request, $ id) Route ('article. Update ') Document update operations
    DELETE /Article/{id} Destroy ($ id) Route ('article. destroy ') Delete an article
    • Note:

      • If the form is to store an article, action = "route ('article. store')" corresponds to the URL

      • When accessing localhost: 8000/article, the URL corresponding to route ('article. index') is accessed.

    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.