| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace App\Providers;
- /*
- * AppServiceProvider — View Composer для siteSettings + Gate-регистрация прав доступа.
- *
- * Gates регистрируются для всех ключей PermissionService::keys().
- * В Blade: @can('cars.edit') ... @endcan
- * В контроллерах: $this->authorize('cars.edit')
- * В AdminLTE меню: 'can' => 'cars.view' (GateFilter включён по умолчанию)
- */
- use App\Models\Setting;
- use App\Models\User;
- use App\Services\PermissionService;
- use Illuminate\Support\Facades\Gate;
- use Illuminate\Support\Facades\View;
- use Illuminate\Support\ServiceProvider;
- class AppServiceProvider extends ServiceProvider
- {
- public function register(): void {}
- public function boot(): void
- {
- // View Composer: настройки сайта в layout, шапке, подвале и страницах каталога
- View::composer(
- [
- 'layouts.app',
- 'layouts.partials._header',
- 'layouts.partials._footer',
- 'pages.catalog',
- 'pages.car',
- ],
- function ($view) {
- $view->with('siteSettings', Setting::all());
- }
- );
- // Gates: регистрируем gate для каждого ключа разрешения
- foreach (PermissionService::keys() as $permission) {
- Gate::define($permission, function (User $user) use ($permission) {
- return $user->hasPermission($permission);
- });
- }
- }
- }
|