代码拉取完成,页面将自动刷新
<?php
namespace App\Admin;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Config;
use Illuminate\Http\Request;
use App\Admin\Models\User as AdminUserModel;
class AdminServiceProvider extends ServiceProvider
{
private static $adminGuardName = 'admin-token';
/**
* 启动服务
*/
public function boot(): void
{
if (!config('admin.enabled')) {
return;
}
// 注册看守器
$this->registerGuard();
Auth::viaRequest(static::$adminGuardName, [$this, 'guard']);
// 注册路由
$this->registerRoutes();
}
public function registerGuard()
{
Config::set('auth.guards.admin', [
'driver' => static::$adminGuardName,
'provider' => 'admin',
]);
Config::set('auth.providers.admin', [
'driver' => 'eloquent',
'model' => App\Admin\Models\User::class,
]);
}
/**
* 注册后台路由
*/
protected function registerRoutes()
{
Route::middlewareGroup('admin.api', config('admin.middleware', []));
Route::group([
'domain' => config('admin.domain', null),
'namespace' => 'App\Admin\Controllers',
'prefix' => config('admin.path', 'admin-api'),
'middleware' => 'admin.api',
], function () {
// $this->loadRoutesFrom(__DIR__.'/routes.php');
$this->loadRoutesFrom(base_path('routes/admin.php'));
});
}
/**
* 注册后台看守器
*/
public function guard(Request $request)
{
$token = Admin::getAuthorization($request);
if( empty($token) ){
return null;
}
$uid = Redis::get($token);
if( $uid==null ){
return null;
}
return AdminUserModel::where('id', $uid)->first();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。