43 lines
1 KiB
PHP
43 lines
1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Domain\PlannableItem\Policies;
|
||
|
|
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Models\PlannableItem;
|
||
|
|
use App\Models\Trip;
|
||
|
|
|
||
|
|
class PlannableItemPolicy
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Determine if the user can create a plannable item for the given trip
|
||
|
|
*/
|
||
|
|
public function create(User $user, Trip $trip): bool
|
||
|
|
{
|
||
|
|
return $trip->created_by_user_id === $user->id;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Determine if the user can view the plannable item
|
||
|
|
*/
|
||
|
|
public function view(User $user, PlannableItem $plannableItem): bool
|
||
|
|
{
|
||
|
|
return $plannableItem->trip->created_by_user_id === $user->id;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Determine if the user can update the plannable item
|
||
|
|
*/
|
||
|
|
public function update(User $user, PlannableItem $plannableItem): bool
|
||
|
|
{
|
||
|
|
return $plannableItem->trip->created_by_user_id === $user->id;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Determine if the user can delete the plannable item
|
||
|
|
*/
|
||
|
|
public function delete(User $user, PlannableItem $plannableItem): bool
|
||
|
|
{
|
||
|
|
return $plannableItem->trip->created_by_user_id === $user->id;
|
||
|
|
}
|
||
|
|
}
|