在/app/Http/Controller/
文件夹下创建了一个Admin
文件夹
-
在项目
routes
目录下添加路由文件admin.php
。 -
修改
/app/providers/RouteServiceProvider.php
文件添加路由方法
protected function mapAdminRoutes()
{
Route::prefix('admin')
->middleware('admin')
->namespace($this->namespace.'\Admin')
->group(base_path('routes/admin.php'));
}
将添加的路由方法加入map
方法中执行
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapAdminRoutes(); // 添加执行的路由方法
}
- 在
/app/Http/Kernel.php
中添加admin
类名及其路径
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
// 根据之前设置的路由规则名(admin)对应添加admin类名,并指向路由验证路径
'admin' => \App\Http\Middleware\VerifyAdmin::class,
];
- 在
/app/Http/Middleware/
文件夹下创建VerifyAdmin.php
,并写入验证代码
<?php
namespace App\Http\Middleware;
use Closure;
class VerifyAdmin
{
public function handle($request, Closure $next)
{
// if ("判断条件") {
return $next($request);
// }
// 返回跳转到网站首页
// return redirect('/');
}
}
这样就新增了一个名为admin
的路由文件
网友评论