2026-07-07 13:00:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
|
|
use App\Models\Product;
|
|
|
|
|
use App\Models\Recipe;
|
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Uwil\LaravelCommon\Support\InertiaSharedRegistry;
|
|
|
|
|
|
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap any application services.
|
|
|
|
|
*/
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
|
|
|
|
InertiaSharedRegistry::add('auth.policies', function () {
|
|
|
|
|
$localModels = [
|
|
|
|
|
Product::class,
|
|
|
|
|
Recipe::class,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$localPolicies = [];
|
|
|
|
|
foreach ($localModels as $model) {
|
|
|
|
|
$key = Str::camel(Str::plural(class_basename($model)));
|
|
|
|
|
|
|
|
|
|
$localPolicies[$key] = [
|
2026-07-09 10:06:36 +02:00
|
|
|
'viewAny' => Gate::allows('viewAny', $model),
|
|
|
|
|
'create' => Gate::allows('create', $model),
|
|
|
|
|
'viewTrash' => Gate::allows('viewTrash', $model),
|
2026-07-07 13:00:40 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $localPolicies;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|