CreateRequest::authorize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Innoflash\Events\Http\Requests\Guest;
4
5
use FaithGen\SDK\Helpers\Helper;
6
use Illuminate\Auth\Access\AuthorizationException;
7
use Illuminate\Foundation\Http\FormRequest;
8
use Innoflash\Events\Services\EventsService;
9
10
class CreateRequest extends FormRequest
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @param EventsService $eventsService
16
     * @return bool
17
     */
18
    public function authorize(EventsService $eventsService)
19
    {
20
        return $eventsService->getEvent() && $this->user()->can('view', $eventsService->getEvent());
21
    }
22
23
    /**
24
     * Get the validation rules that apply to the request.
25
     *
26
     * @return array
27
     */
28
    public function rules()
29
    {
30
        return [
31
            'title' => 'required|string|min:2|max:15',
32
            'name' => 'required|string',
33
            'event_id' => Helper::$idValidation,
34
            'image' => 'required|base64image',
35
        ];
36
    }
37
38
    public function failedAuthorization()
39
    {
40
        throw new AuthorizationException('You are not allowed to transact on this event');
41
    }
42
}
43