56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\User;
|
|
use App\Models\Item;
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
class ItemPolicy
|
|
{
|
|
use HandlesAuthorization;
|
|
|
|
/**
|
|
* Determine whether the user can view any items.
|
|
*/
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return $user->can('inventory.view') || $user->can('inventory.update');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the item.
|
|
*/
|
|
public function view(User $user, Item $item): bool
|
|
{
|
|
return $user->tenant_id === $item->tenant_id
|
|
&& ($user->can('inventory.view') || $user->can('inventory.update'));
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create items.
|
|
*/
|
|
public function create(User $user): bool
|
|
{
|
|
return $user->can('inventory.create');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the item.
|
|
*/
|
|
public function update(User $user, Item $item): bool
|
|
{
|
|
return $user->tenant_id === $item->tenant_id
|
|
&& $user->can('inventory.update');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the item.
|
|
*/
|
|
public function delete(User $user, Item $item): bool
|
|
{
|
|
return $user->tenant_id === $item->tenant_id
|
|
&& $user->can('inventory.delete');
|
|
}
|
|
}
|