CreateRequest::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace FaithGen\News\Http\Requests;
4
5
use FaithGen\News\Models\News;
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', News::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
            'title' => 'required|string|between:3,255',
30
            'news' => 'required|string',
31
            'image' => 'required|base64image',
32
        ];
33
    }
34
35
    protected function failedAuthorization()
36
    {
37
        throw new AuthorizationException('You need to upgrade subscription to be able to send more than 2 news articles');
38
    }
39
}
40