Home > Article > PHP Framework > How to add a routing file in laravel
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
. 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')); }
Then find the map method, add this sentence $this->mapAppRoutes();
Add the App class name and its path in /app/Http/Kernel.php
'app' => \App\Http\Middleware\VerifyApp::class
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('/'); } }
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
Newly added to the file These methods
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');
##Related recommendations:
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!