<?php namespace App\Policies; use App\Models\Brand; use App\Models\Permission; use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization; use Illuminate\Auth\Access\Response; use Illuminate\Support\Facades\Auth; class BrandPolicy { 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','=','brands_viewAny')) ? Response::allow() : Response::deny('you are not the chosen one'); } /** * Determine whether the user can view any models. * * @return Response */ public function viewAny_deleted(): Response { return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_viewAny_deleted')) ? Response::allow() : Response::deny('you are not the chosen one'); } /** * Determine whether the user can view the model. * * @param Brand $Brand * @param User $model * @return Response */ public function view(): Response { return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_view')) ? Response::allow() : Response::deny('you are not the chosen one'); } /** * Determine whether the user can create models. * * @return Response */ public function create(): Response { return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_create')) ? Response::allow() : Response::deny('you are not the chosen one'); } /** * Determine whether the user can update the model. * * @param Brand $Brand * @return Response */ public function edit(): Response { return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_edit')) ? Response::allow() : Response::deny('you are not the chosen one'); } /** * Determine whether the user can delete the model. * * @param Brand $Brand * @return Response */ public function delete(): Response { return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_delete')) ? Response::allow() : Response::deny('you are not the chosen one'); } /** * Determine whether the user can restore the model. * * @param Brand $Brand * @return Response|bool */ public function restore() { return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_restore')) ? Response::allow() : Response::deny('you are not the chosen one'); } /** * Determine whether the user can permanently delete the model. * * @param Brand $Brand * @return Response|bool */ public function delete_force() { return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_delete_force')) ? Response::allow() : Response::deny('you are not the chosen one'); } }