before(function (Authenticatable $user, string $ability) { try { if (method_exists($user, 'hasPermissionTo')) { return $user->hasPermissionTo($ability) ?: null; } } catch (NotExistException $e) { } }); } /** * 注册一个服务提供者 * * @return void */ public function register() { $this->app->singleton('auth:admin', function ($app) { return new AuthService('admin', app(AccountRepository::class)); }); $this->app->register(RouteServiceProvider::class); $this->app->register(MiddlewareServiceProvider::class); } }