ldc-crm/app/Policies/CustomerPolicy.php
2021-09-14 12:12:30 +02:00

40 lines
1,013 B
PHP

<?php
namespace App\Policies;
use App\Models\Customer;
use App\Models\Service;
use App\Policies\Rules\UserStaticRules as USR;
use Illuminate\Auth\Access\HandlesAuthorization;
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
class CustomerPolicy extends RootPolicy
{
use HandlesAuthorization;
/**
* Init policies on call
*
* @return void
*/
public function setPolicies()
{
/**
* This first rule to return true in a policy action authorises the action
*/
$this->policies = [
'customer' => [
'viewAny' => USR::make('everyOne'),
'view' => USR::make('everyOne'),
'create' => USR::make('noOne'),
'update' => USR::make('noOne'),
'delete' => USR::make('everyOne')
]
];
}
public function customerBelongsToService(Service $service, Customer $customer)
{
return !\is_null($customer->login($service->brand));
}
}