Create the project according to phP-Laravel and run it on the server (nginx, Apache) (with directory structure).

What is routing?

  • The user request is submitted to the specified controller and method according to the pre-planned scheme for processing.

  • Route configuration file: routes/web.php

Ii. Definitions of the four basic Routes (Focus on)

  • Routing template

    // Route:: request method (' URL ', anonymous function); Route:: Request method (' URL ', 'controller name @ operation method '); Route:: Request method (' URL ', 'command space/controller name @ operation method '); Route:: Request mode ('/url', anonymous function); Select Route::get($uri, $callback); Insert Route::post($uri, $callback); Update Route::put/patch($uri, $callback); Delete Route::delete($uri, $callback); Among the four basic routes, only the GET request mode does not perform CSRF authentication. Other request modes require CSRF authenticationCopy the code

  • Routing Example (1)

  • Each route is a form of request

    Route::get('/get', function () {return 'get '; }); Route::post('/post', function () {return 'post request '; }); // put/patch Route::put('/put', function () {return 'put request '; }); Route::delete('/delete', function () {return 'delete request '; });Copy the code
  • Example effects – Open through website:

    • GetRequest, noCSRFvalidation

    • PostRequest to walkPostman, the browser defaults toGetThe request.

  • Example effect – Postman:

    • GetRequest, noCSRFvalidation

    • PostAt the request of quote419Error, required for all of the latter requestsCSRFVerify, look ahead to the solution.


  • Routing Example (2)

  • A route supports multiple request modes

    Route::get('/req', function () {return 'get request '; }); Route::post('/req', function () {return 'post request '; }); // put/patch Route::put('/req', function () {return 'put request '; }); Route::delete('/req', function () {return 'delete request '; });Copy the code
    • Example effects – Open through website:

    • A Get request

  • Example effect – Postman:

    • GetRequest, noCSRFvalidation

    • PostAt the request of quote419Error, required for all of the latter requestsCSRFVerify, look ahead to the solution.


  • Resolving routing ExamplesCSRFValidation issues

  • Php-laravel CSRF introduction and Usage (and unvalidation of CSRF)

  • Find the app/Http/Middleware/VerifyCsrfToken $except field in the PHP file, add do not need to undertake CSRF verification routing:

    Protected $except = [// remove routing rules from array // remove routing rules without CSRF validation '/post', '/req'];Copy the code
  • Try the request again

Three,matchConfiguring routes (Focus on)

  • Multiple request types are configured for a single route

    Route::match(['get', 'post'], '/req', function () {// return 'match Route definition '; dump($_SERVER); });Copy the code
  • Example effect – Postman:

Four,anyConfiguring routes (It is not recommended for practical use)

  • A single route adaptively supports all requests

    Route::any('/req', function () {// return 'any Route definition '; dump($_SERVER); });Copy the code
  • Example effect – Postman:

Five,Routing alias

Vi.Route group – Route prefix

Seven,Controller creation (Routing association, routing namespace grouping)

Eight,Routing parameters

Nine,Interface request parameter retrieval (multiple ways)

Ten,The interface request returns JSON data

Eleven,Route (interface) redirection

Twelve,Viewing a custom Route List (PHP Artisan Route: List)