UpdateRequest::authorize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
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 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Innoflash\Events\Http\Requests;
4
5
use Illuminate\Auth\Access\AuthorizationException;
6
use Illuminate\Foundation\Http\FormRequest;
7
use Innoflash\Events\Services\EventsService;
8
9
class UpdateRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @return bool
15
     */
16
    public function authorize(EventsService $eventsService)
17
    {
18
        return $eventsService->getEvent()
19
            && $this->user()->can('update', $eventsService->getEvent());
20
    }
21
22
    /**
23
     * Get the validation rules that apply to the request.
24
     *
25
     * @return array
26
     */
27
    public function rules()
28
    {
29
        return [
30
            'name'        => 'required|string',
31
            'description' => 'required|string',
32
            'location'    => 'required|array',
33
            'start'       => 'required|date_format:Y-m-d H:i',
34
            'end'         => 'required|date_format:Y-m-d H:i',
35
            'published'   => 'required|boolean',
36
            'url'         => 'url',
37
            'video_url'   => 'url',
38
            'banner'      => 'base64image',
39
        ];
40
    }
41
42
    public function failedAuthorization()
43
    {
44
        throw new AuthorizationException('You are not allowed to update this event');
45
    }
46
}
47