TogglePublishRequest::failedAuthorization()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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 TogglePublishRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @param  \Innoflash\Events\Services\EventsService  $eventsService
15
     *
16
     * @return bool
17
     */
18
    public function authorize(EventsService $eventsService)
19
    {
20
        return $eventsService->getEvent()
21
            && $this->user()->can('update', $eventsService->getEvent());
22
    }
23
24
    /**
25
     * Get the validation rules that apply to the request.
26
     *
27
     * @return array
28
     */
29
    public function rules()
30
    {
31
        return [
32
            'published' => 'required|boolean',
33
        ];
34
    }
35
36
    public function failedAuthorization()
37
    {
38
        throw new AuthorizationException('You are not allowed to update this event');
39
    }
40
}
41