ChecksPermissions::hasPermissionTo()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 2
b 1
f 0
1
<?php
2
3
namespace Acacha\Events\Http\Requests\Traits;
4
5
use Auth;
6
7
/**
8
 * Trait ChecksPermissions.
9
 *
10
 * @package Acacha\Events\Http\Requests\Traits
11
 */
12
trait ChecksPermissions
13
{
14
    /**
15
     * Logged as permission to.
16
     *
17
     * @param $permission
18
     * @return bool
19
     */
20
    protected function hasPermissionTo($permission)
21
    {
22
        if (Auth::user()->hasPermissionTo($permission)) {
23
            return true;
24
        }
25
        return false;
26
    }
27
28
    /**
29
     * Owns model.
30
     *
31
     * @param $model
32
     * @return bool
33
     */
34
    protected function owns($model, $field = 'user_id')
35
    {
36
        if (Auth::user()->id == $this->$model->$field) {
37
            return true;
38
        }
39
        return false;
40
    }
41
}
42