wip
This commit is contained in:
@@ -5,10 +5,14 @@ declare(strict_types=1);
|
||||
namespace Toby\Architecture\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Toby\Domain\Policies\HolidayPolicy;
|
||||
use Toby\Eloquent\Models\Holiday;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected $policies = [];
|
||||
protected $policies = [
|
||||
Holiday::class => HolidayPolicy::class
|
||||
];
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
|
16
app/Domain/Policies/HolidayPolicy.php
Normal file
16
app/Domain/Policies/HolidayPolicy.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Policies;
|
||||
|
||||
use Toby\Domain\Enums\Role;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class HolidayPolicy
|
||||
{
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->role == Role::AdministrativeApprover || $user->role == Role::Administrator;
|
||||
}
|
||||
}
|
@@ -5,7 +5,9 @@ declare(strict_types=1);
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\Policies\HolidayPolicy;
|
||||
use Toby\Eloquent\Models\Holiday;
|
||||
use Toby\Infrastructure\Http\Requests\HolidayRequest;
|
||||
use Toby\Infrastructure\Http\Resources\HolidayFormDataResource;
|
||||
@@ -13,14 +15,18 @@ use Toby\Infrastructure\Http\Resources\HolidayResource;
|
||||
|
||||
class HolidayController extends Controller
|
||||
{
|
||||
public function index(): Response
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$holidays = Holiday::query()
|
||||
->orderBy("date")
|
||||
->get();
|
||||
|
||||
$user = $request->user();
|
||||
return inertia("Holidays/Index", [
|
||||
"holidays" => HolidayResource::collection($holidays),
|
||||
"can" => [
|
||||
"create" => $user->can("create", Holiday::class)
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user