ChecksPermissions   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 34
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A owns() 0 9 2
A hasPermissionTo() 0 7 2
1
<?php
2
3
namespace App\Http\Requests\Traits;
4
5
use Illuminate\Support\Facades\Auth;
6
7
/**
8
 * Trait ChecksPermissions.
9
 */
10
trait ChecksPermissions
11
{
12
    /**
13
     * Logged as permission to.
14
     *
15
     * @param $permission
16
     *
17
     * @return bool
18
     */
19
    protected function hasPermissionTo($permission)
20
    {
21
        if (Auth::user()->hasPermissionTo($permission)) {
22
            return true;
23
        }
24
25
        return false;
26
    }
27
28
    /**
29
     * Owns model.
30
     *
31
     * @param $model
32
     *
33
     * @return bool
34
     */
35
    protected function owns($model, $field = 'user_id')
36
    {
37
        //todo
38
39
        if (Auth::user()->id == $this->$model->$field) {
40
            return true;
41
        }
42
43
        return false;
44
    }
45
}
46