CreateRequest::authorize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace FaithGen\Gallery\Http\Requests;
4
5
use FaithGen\Gallery\Models\Album;
6
use Illuminate\Auth\Access\AuthorizationException;
7
use Illuminate\Foundation\Http\FormRequest;
8
9
class CreateRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @return bool
15
     */
16
    public function authorize()
17
    {
18
        return $this->user()->can('create', Album::class);
19
    }
20
21
    /**
22
     * Get the validation rules that apply to the request.
23
     *
24
     * @return array
25
     */
26
    public function rules()
27
    {
28
        return [
29
            'name' => 'required|string|max:100',
30
            'description' => 'required|string',
31
        ];
32
    }
33
34
    protected function failedAuthorization()
35
    {
36
        if (strcmp(auth()->user()->account->level, 'Free') === 0) {
37
            $message = 'You need to upgrade to able to create more than one album this month';
38
        } else {
39
            $message = 'You need to upgrade further to be able to create more than 5 albums this month';
40
        }
41
        throw new AuthorizationException($message, 403);
42
    }
43
}
44