Laravel8.x多路由文件设置相比之前的laravel6多路由文件设置和laravel5.8多路由文件设置有所改变,看了下\app\Providers\RouteServiceProvider.php文件,比原来的更加简洁的,以下教大家如何设置多文件路由,对路由进行分组,本文以laravel8.5为例。
1、首先在\routes文件夹下新增admin.php路由文件,然后他相应路由粘贴过来

<?php
/**
*
* User: jyblogs
* Date: 2021/4/12
* Email: <2938039696@qq.com>
* 后台路由文件
**/
use Illuminate\Support\Facades\Route;
Route::prefix('ladmin')->name("ladmin.")->group(function () {
Route::get('/index', [App\Http\Controllers\Admin\IndexController::class, 'index'])->name('index.index'); //后台首页
});
?>2、修改\app\Providers\RouteServiceProvider.php文件,加入如下代码

<?php
.....
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
Route::namespace($this->namespace)
->group(base_path('routes/admin.php'));
});
}
.....
?>这样就可以实现多文件路由文件,方面后期项目路由管理。laravel5.8设置方法可以参考这边文章:laravel中新增路由文件
关于简忆
简忆诞生的故事



粤ICP备16092285号
文章评论(0)