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

Request   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authorizeResource() 0 8 2
A isEditing() 0 4 1
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