36 lines
948 B
PHP
36 lines
948 B
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Enums\RoleEnum;
|
|
use App\Models\Delivery;
|
|
use App\Models\User;
|
|
|
|
class DeliveryPolicy
|
|
{
|
|
public function view(User $user, Delivery $delivery)
|
|
{
|
|
if($user->role == RoleEnum::DRIVER) {
|
|
return $delivery->user_id == $user->id && $delivery->warehouse_id == $user->warehouse_id;
|
|
}
|
|
|
|
return $user->warehouse_id == $delivery->warehouse_id;
|
|
}
|
|
|
|
public function create(User $user)
|
|
{
|
|
return $user->role == RoleEnum::ADMIN || $user->role == RoleEnum::DISPATCHER;
|
|
}
|
|
|
|
public function update(User $user, Delivery $delivery)
|
|
{
|
|
return ($user->role == RoleEnum::ADMIN || $user->role == RoleEnum::DISPATCHER) &&
|
|
$delivery->warehouse_id == $user->warehouse_id;
|
|
}
|
|
|
|
public function delete(User $user, Delivery $delivery)
|
|
{
|
|
return $user->role == RoleEnum::ADMIN && $delivery->warehouse_id == $user->warehouse_id;
|
|
}
|
|
}
|