Laravel Routing (Router) graphic detail

Source: Internet
Author: User
This article mainly introduces the laravel of the route (router) graphic detailed, has a certain reference value, now share to everyone, have the need for friends can refer to

Laravel Routing (Router) graphic detail

Laravel-based routing:

Inside the/routes/web.php, write a

Route::get ('/hello ', function () {    return ' Hello, can you hear me? ';});

And then you can do it in the browser.

Postman can also be seen directly

Original:

Let's try calling the controller first:

Route::get ('/menu ', ' menu\menuindexcontroller@index ');

This is what the direct GET request sends about, call the Staticpagescontroller controller's about method

<?phpnamespace app\http\controllers\menu;//Modify namespace use app\http\controllers\controller;//reference base Controlleruse Illuminate\http\request;class Menuindexcontroller extends controller{    //Public    function Index () {        Return view (' Menu/index ');}    }

Jump to view:

@extends (' Layouts.default ') @section (' content ') 

Browser effects:

The routes defined in the routes/api.php file are nested in a routing middleware group through App/providers/routesserviceprovider processing, and in this routing middleware group, all routes are automatically added/API prefixes. So you don't need to manually add each route to the routing file, you can modify the route prefix and other routing middleware group options by editing the Routeserviceprovider class;

This lump do not change, the bottom of things changed not know what will happen magic things;

There are times when you need to register a route to respond to multiple HTTP request actions-This can be done using the match method. Alternatively, you can use the any method to register a route to respond to all HTTP request actions:

Route::match ([' Get ', ' post '], ' returnreturn ', ' Menu\menuindexcontroller@returnreturn '); Route::any (' Returnany ', ' menu\menuindexcontroller@returnany ');

Route redirection:

If you need to define a redirect to another URI route, you can use the Route::redirect

Route::redirect (' motherfucker ', ' menu ', 301);

Browser input motherfucker will jump to the menu;

301 is a status code, default 301, Original:

Of course there is a need to jump directly to the view layer (views), and then the rest of the data (maybe whole) is provided by the API to get, then the direct jump to the view of the route is so playing:

Route::view (' Staticview ', ' Static_pages/staticview ');

Note that the Static_pages/staticview here is a forward slash, and the backslash will error that can not found Static_pages\staticview;

Static pages are located at:

Browser Direct Access Effects:

And, of course, there's another kind of operation, that is, Route::view passes the third argument for data rendering in the view

Route::view (' Staticviewdata ', ' static_pages/staticviewdata ', [' name ' = ' Jack ', ' like ' and ' money ']);

Passing an array of the past is naturally [' name ' = ' Jack ', ' like ' and ' money '],

on page usage:

@extends (' Layouts.default ') @section (' content ') 

Then the browser effect:

Of course you want to skin, that is naturally not possible:

Route::view (' Staticviewdata ', ' static_pages/staticviewdata ', [' name ' = ' Jack ', ' like ' and ' money ', ' jump ' and ' = ') <a href= "/about" > "]);

The source code will be labeled as normal text parsing, plus < &rt;

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.