Completed
Push — master ( a19a47...15bbc5 )
by Arjay
15:59
created

Request::authorizeResource()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yajra\CMS\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
7
abstract class Request extends FormRequest
8
{
9
    /**
10
     * Check if user is authorized to perform the action.
11
     *
12
     * @param string $resource
13
     * @return bool
14
     */
15
    protected function authorizeResource($resource)
16
    {
17
        if ($this->isEditing($resource)) {
18
            return $this->user()->can($resource . '.update');
19
        }
20
21
        return $this->user()->can($resource . '.create');
22
    }
23
24
    /**
25
     * Check if request is for update or create.
26
     * Editing will be identified if route parameter exists.
27
     *
28
     * @param string $resource
29
     * @return bool
30
     */
31
    protected function isEditing($resource)
32
    {
33
        return !! $this->route($resource);
34
    }
35
}
36