Home >PHP Framework >Laravel >Detailed explanation about laravel automatic routing

Detailed explanation about laravel automatic routing

藏色散人
藏色散人forward
2021-06-16 14:53:252418browse

The following tutorial column will introduce laravel automatic routing to you. I hope it will be helpful to friends in need!

Detailed explanation about laravel automatic routing                                                                                                                                          

1. Function

Advantages 1. Automatically match the controllerFor example:

URL: localhost/home/hello/index/id/name/……


Controller: App\Http\Controllers\Hello.php

Method: index is the method under Hello.php

Parameters: id, name... are all parameters, automatically matched to the parameters in the controller method

Advantage 2. Routing can be configured in the original routes->api.php and routes->web.php

Advantage 3. Routes specified in api or web will be matched first



## 2. Installation

composer require xindong888/laravel-router

3. Usage method one

1. Use composer to load composer require xindong888/laravel-router

2. Enter the configuration folder config->app.php

<?php
[
&#39;providers&#39; => [
//.................注释掉原有的路由服务提供者
//App\Providers\RouteServiceProvider::class,
//.................添加万能路由服务提供者
xindong888\Laravel\Providers\RouteServiceProvider::class
]]
?>
four .Usage method two

1. Use app->Providers->RouteServiceProvider to inherit xindong888\Laravel\Providers\RouteServiceProvider
2. Clean up the code in boot() and add parent::boot() ;

class RouteServiceProvider extends \xindong888\Laravel\Providers\RouteServiceProvider
{
    public function boot()
    {
        parent::boot();
    }
}

Related recommendations:

The latest five Laravel video tutorials

The above is the detailed content of Detailed explanation about laravel automatic routing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete