ldc-gen-game-web/app/Providers/AuthServiceProvider.php

53 lines
1.5 KiB
PHP
Raw Normal View History

2020-10-21 15:26:21 +02:00
<?php
namespace App\Providers;
use App\Auth\CrmUserProvider;
2023-11-23 17:31:28 +01:00
use App\Enums\Users\RoleEnum;
2023-11-29 17:00:54 +01:00
use App\Models\Customer;
2023-11-30 11:10:02 +01:00
use App\Models\FaqQuestion;
use App\Models\Product;
2023-11-23 17:31:28 +01:00
use App\Models\User;
2020-10-21 15:26:21 +02:00
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
2023-11-23 17:31:28 +01:00
use Illuminate\Support\Facades\Gate;
2020-10-21 15:26:21 +02:00
class AuthServiceProvider extends ServiceProvider
{
/**
2023-11-23 17:31:28 +01:00
* The model to policy mappings for the application.
2020-10-21 15:26:21 +02:00
*
2023-11-23 17:31:28 +01:00
* @var array<class-string, class-string>
2020-10-21 15:26:21 +02:00
*/
protected $policies = [];
2020-10-21 15:26:21 +02:00
/**
* Register any authentication / authorization services.
*
* @return void
*/
2023-11-23 17:31:28 +01:00
public function boot(): void
2020-10-21 15:26:21 +02:00
{
2023-11-23 17:31:28 +01:00
Gate::define('isConceptor', function (User $user) {
return $user->role === RoleEnum::conceptor;
});
Gate::define(
'fo.showProducts',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
2023-11-30 11:10:02 +01:00
fn (User|Customer|null $user) => view()->exists('theme::pages.products') and
(bool)Product::getCached()->count()
);
Gate::define(
'fo.showFaq',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
fn (User|Customer|null $user) => view()->exists('theme::pages.faq') and
(bool)FaqQuestion::getCached()->count()
);
$this->app->auth->provider('crm', function ($app, array $config) {
return new CrmUserProvider($app['hash'], $config['model']);
});
2020-10-21 15:26:21 +02:00
}
}