"laravel5.1-0.0.4" easy to implement restful style routing and control

Source: Internet
Author: User

From my book of Jane: Http://www.jianshu.com/users/85c8826ce087/latest_articles
will take the curd operation of the article as an example, this article only involves the basic routing and Controller > methods, implementation, will continue to explain later.

1. New route
    • Add in app/http/routes.php:
      Route::resource (' article ', ' Articlecontroller ');

      • This resource route contains the Zi Lu by looking at the following sample table;

    2. Controller
      • Creating a controller from a terminal
        PHP Artisan Make:controller Articlecontroller

      • Get the Controller class App/http/controllers/articlecontroller

      • If you want to implement a controller file after creating a folder under App/http/controllers, create a controller class inside, you can use the command:
        PHP Aritsan Make:controller Article/articlecontroller

      • Example of a controller class:

     3. (Routing---> Controller) example table for restful control relationships:
     
     
    Request Method Routing Address corresponding Controller method corresponding route name Current Role
    GET /article Index () Route (' Article.index ') Show List of articles
    GET /article/ Create () Route (' Article.create ') Article new page
    POST /article Store (Request $request) Route (' Article.store ') Article Store Operations
    GET /article/{id} Show ($id) Route (' Article.index ') Article details show
    GET /article/{id}/edit Edit ($ID) Route (' Article.edit ') Article edit page
    Put/patch /article/{id}/ Update (Request $request, $id) Route (' Article.update ') Article Update action
    DELETE /article/{id} Destroy ($ID) Route (' Article.destroy ') Article Delete action
      • Note:

        • If the form form is to store the article then action = "route (' Article.store ')" to correspond to the URL

        • Access to localhost:8000/article is the URL of the route (' Article.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.