Home  >  Article  >  PHP Framework  >  How to add a routing file in laravel

How to add a routing file in laravel

藏色散人
藏色散人forward
2021-05-24 15:38:033542browse

The following tutorial column from laravel will introduce how to add routing files in laravel. I hope it will be helpful to friends in need!

Recently, the company's projects have used the laravel framework. Some of the functions used will depend on the problems encountered. Gradually improve

Add routing files under the routes folder. Mine is used to write app interfaces. I am lazy and just name it app.php
How to add a routing file in laravel
. After adding it, you need to configure it. File, find the app/Providers/RouteServiceProvider.php file, add the following

protected function mapAppRoutes()
{
    Route::prefix('app')
        ->middleware('app')
        ->namespace($this->namespace.'\App')
        ->group(base_path('routes/app.php'));
}

How to add a routing file in laravel
Then find the map method, add this sentence $this->mapAppRoutes();
How to add a routing file in laravel

Add the App class name and its path in /app/Http/Kernel.php
'app' => \App\Http\Middleware\VerifyApp::class
How to add a routing file in laravel
Create VerifyApp.php in the /app/Http/Middleware/ folder and write the verification code

class VerifyApp
{
public function handle($request, Closure $next)
{
// if (“判断条件”) {
return n e x t ( next(next(request);
// }

    // 返回跳转到网站首页
    // return redirect('/');
}
}

How to add a routing file in laravel

so that the route you defined can be

My file is placed in app/Http/Controllers/App

Create a new file UserController.php, as shown in the figure
How to add a routing file in laravel
Newly added to the file These methods
How to add a routing file in laravel
can be defined in the app.php route. You can write as many as you want

Route::any('login', 'UserController@login');
Route::any('register', 'UserController@register');
Route::any('sendSms', 'UserController@sendSms');
Route::any('check_mobile', 'UserController@checkMobile');

How to add a routing file in laravel

##Related recommendations:

The latest five Laravel video tutorials

The above is the detailed content of How to add a routing file in laravel. For more information, please follow other related articles on the PHP Chinese website!

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