Lager-v3/app/Policies/LoanPolicy.php

86 lines
2.1 KiB
PHP
Raw Normal View History

2022-09-28 07:38:08 +00:00
<?php
namespace App\Policies;
use App\Models\Permission;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Auth\Access\Response;
use Illuminate\Support\Facades\Auth;
class LoanPolicy
{
use HandlesAuthorization;
/**
* Create a new policy instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine whether the user can view any models.
*
* @return Response
*/
public function viewAny(): Response
{
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','loans_viewAny'))
? Response::allow()
: Response::deny('you are not the chosen one');
}
/**
* Determine whether the user can create models.
*
* @return Response
*/
public function create_user(): Response
{
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','loans_create_user'))
? Response::allow()
: Response::deny('you are not the chosen one');
}
/**
* Determine whether the user can create models.
*
* @return Response
*/
public function create_laptop(): Response
{
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','loans_create_laptop'))
? Response::allow()
: Response::deny('you are not the chosen one');
}
/**
* Determine whether the user can update the model.
*
* @return Response
*/
public function adjust(): Response
{
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','loans_adjust'))
? Response::allow()
: Response::deny('you are not the chosen one');
}
/**
* Determine whether the user can delete the model.
*
* @return Response
*/
public function return(): Response
{
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','loans_return'))
? Response::allow()
: Response::deny('you are not the chosen one');
}
}