Home > PHP Framework > Laravel > body text

How to add a routing file in laravel

藏色散人
Release: 2021-05-25 09:16:53
forward
3550 people have browsed it

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'));
}
Copy after login

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('/');
}
}
Copy after login

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');
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template