File: D:/HostingSpaces/SBogers10/blije-gasten.komma.pro/app/Komma/Base/Policy.php
<?php
namespace App\Komma\Base;
use App\Helpers\KommaHelpers;
use App\Komma\Users\Models\KmsUserRole;
use App\Komma\Users\Models\KmsUser;
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Database\Eloquent\Model;
abstract class Policy
{
use HandlesAuthorization;
/*
|--------------------------------------------------------------------------
| General C.R.U.D. actions authorization
|--------------------------------------------------------------------------
|
| Here you handle basic authorization create, read, update, delete actions
*/
/**
* Determine if it is allowed to view all resources
*
* @param KmsUser|null $user
* @return bool
*/
public function index(KmsUser $user): bool
{
$result = $user->isAtLeast(KmsUserRole::Editor);
return $result;
}
/**
* Determine if it is allowed to view a specific resource
*
* @param KmsUser|null $user
* @return bool
*/
public function show(KmsUser $user, $modelToShow): bool
{
return $user->isAtLeast(KmsUserRole::Editor);
}
/**
* Determine if it is allowed show a form to edit a resource.
* This usually means that the user did view the model to be edited and got past
* the show authorisation. Then he edited a form to change the model and pressed
* save. After he pressed save he will trigger this edit authorisation
*
* @param KmsUser|null $user
* @return bool
*/
public function edit(KmsUser $user, $modelToEdit): bool
{
return $user->isAtLeast(KmsUserRole::Editor);
}
/**
* Determine if it is allowed to show a form for creating a new resource
*
* @param KmsUser|null $user
* @return bool
*/
public function create(KmsUser $user): bool
{
return $user->isAtLeast(KmsUserRole::Admin);
}
/**
* Determine if it is allowed to store a new resource
* Usually made using a create form.
*
* @param KmsUser|null $user
* @return bool
*/
public function store(KmsUser $user): bool
{
return $user->isAtLeast(KmsUserRole::Editor);
}
/**
* Determine if it is allowed to update an existing resource after editing it
*
* @param KmsUser|null $user
* @return bool
*/
public function update(KmsUser $user): bool
{
return $user->isAtLeast(KmsUserRole::Editor);
}
/**
* Determine if it is allowed to destroy an existing resource
*
* @param KmsUser|null $user
* @return bool
*/
public function destroy(KmsUser $user, $modelToDestroy): bool
{
return $user->isAtLeast(KmsUserRole::Admin);
}
}