Passed
Push — master ( 8475f2...95bd7d )
by Quim González
03:21
created

ChecksPermissions::owns()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 5
rs 9.4285
1
<?php
2
3
namespace App\Http\Requests\Traits;
4
5
use Illuminate\Support\Facades\Auth;
6
7
/**
8
 * Trait ChecksPermissions.
9
 *
10
 * @package Quimgc\Tasks\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)) return true;
23
        return false;
24
    }
25
26
    /**
27
     * Owns model.
28
     *
29
     * @param $model
30
     * @return bool
31
     */
32
    protected function owns($model,$field = 'user_id')
33
    {
34
        //todo
35
        if (Auth::user()->id == $this->$model->$field) return true;
36
        return false;
37
    }
38
}