Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
CustomerPolicy
n/a
0 / 0
n/a
0 / 0
2
n/a
0 / 0
 setPolicies
n/a
0 / 0
n/a
0 / 0
1
 customerBelongsToService
n/a
0 / 0
n/a
0 / 0
1
1<?php
2
3namespace App\Policies;
4
5use App\Models\Customer;
6use App\Models\Service;
7use App\Policies\Rules\UserStaticRules as USR;
8use Illuminate\Auth\Access\HandlesAuthorization;
9use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
10
11/**
12 * @codeCoverageIgnore
13 */
14class CustomerPolicy extends RootPolicy
15{
16    use HandlesAuthorization;
17
18    /**
19     * Init policies on call
20     *
21     * @return void
22     */
23    public function setPolicies()
24    {
25        /**
26         * This first rule to return true in a policy action authorises the action
27         */
28        $this->policies = [
29            'customer' => [
30                'viewAny' => USR::make('everyOne'),
31                'view' => USR::make('everyOne'),
32                'create' => USR::make('noOne'),
33                'update' => USR::make('noOne'),
34                'delete' => USR::make('everyOne')
35            ]
36        ];
37    }
38
39    /**
40     * Check if the customer belongs to the service
41     *
42     * @param Service  $service
43     * @param Customer $customer
44     * @return boolean
45     */
46    public function customerBelongsToService(Service $service, Customer $customer)
47    {
48        return !\is_null($customer->login($service->brand));
49    }
50}