sistem-akademik/app/Policies/UserPolicy.php
2025-04-11 22:56:42 +07:00

69 lines
1.6 KiB
PHP

<?php
namespace App\Policies;
use App\Models\User;
use Illuminate\Auth\Access\Response;
class UserPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->can('view_any_user');
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, User $model): bool
{
return $user->can('view_user');
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->can('create_user');
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, User $model): bool
{
// Users can update themselves, or if they have update_user permission
return $user->id === $model->id || $user->can('update_user');
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, User $model): bool
{
// Prevent users from deleting themselves
return $user->can('delete_user');
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, User $model): bool
{
return $user->can('restore_user');
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, User $model): bool
{
// Prevent users from force deleting themselves
return $user->can('force_delete_user');
}
}