ImageUploadRequest::authorize()   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
eloc 1
nc 1
nop 0
dl 0
loc 3
c 1
b 0
f 0
cc 1
rs 10
1
<?php
2
3
namespace Wingsline\Blog\Http\Requests;
4
5
use Illuminate\Contracts\Validation\Validator;
6
use Illuminate\Foundation\Http\FormRequest;
7
use Illuminate\Http\Exceptions\HttpResponseException;
8
9
class ImageUploadRequest 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 true;
19
    }
20
21
    /**
22
     * Get the validation rules that apply to the request.
23
     *
24
     * @return array
25
     */
26
    public function rules()
27
    {
28
        $size = config('media-library.max_file_size');
29
30
        return [
31
            'image' => [
32
                'required',
33
                'mimes:jpeg,png',
34
                'image',
35
                'max:'.$size,
36
            ],
37
        ];
38
    }
39
40
    protected function failedValidation(Validator $validator)
41
    {
42
        // make sure we return the proper error for easymde
43
        throw new HttpResponseException(
44
            response()->json(['error' => $validator->errors()->first('image')],
45
                422)
46
        );
47
    }
48
}
49