*/ #[\Override] protected $policies = [ // * Policies Exceptions BasketProduct::class => BasketPolicy::class, DiscountDto::class => DiscountPolicy::class, FaqDto::class => FaqPolicy::class, PageDto::class => PagePolicy::class, PickupExceptionDto::class => PickupExceptionPolicy::class, ProductDto::class => ProductPolicy::class, RangeDto::class => RangePolicy::class, Setting::class => SettingPolicy::class, SettingDto::class => SettingPolicy::class, ShopDto::class => ShopPolicy::class, SlideDto::class => SlidePolicy::class, TagDto::class => TagPolicy::class, FetchAndUpsertArcadiaEmployees::class => EmployeePolicy::class, ]; /** * Register any authentication / authorization services. * * @return void */ public function boot() { $this->app->singleton( AppAdminAuthService::class, fn ($app): AppAdminAuthService => new AppAdminAuthService( Auth::guard('backend') ) ); $this->app->singleton( AppCustomerAuthService::class, fn ($app): AppCustomerAuthService => new AppCustomerAuthService( Auth::guard('frontend'), $app->make(CrmService::class) ) ); Auth::shouldUse($this->currentRouteGuard()); Gate::define( 'customerPassOrders', fn (Customer $customer): bool => resolve(ShopperService::class) ->canCustomerPassOrdersApp($customer->getId()) ); $this->registerPolicies(); Gate::guessPolicyNamesUsing(function (string $modelClass) { $context = $this->currentRouteGuard() === 'frontend' ? 'Frontend' : 'Backend'; $classBasename = str_replace('Dto', '', class_basename($modelClass)); $policyClass = "App\\Policies\\{$context}\\{$classBasename}Policy"; return class_exists($policyClass) ? $policyClass : null; }); } private function currentRouteGuard(): string { $request = $this->app->make(Request::class); $defaultGuard = Config::string('auth.defaults.guard', 'frontend'); return match (true) { $request->is('bo', 'bo/*') => 'backend', $request->is('api', 'api/*') => 'api', default => $defaultGuard, }; } }