Passed
Push — master ( ee4194...734cc2 )
by Hamzah
02:15
created

Request::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: shamaseen
5
 * Date: 09/10/18
6
 * Time: 01:01 م.
7
 */
8
9
namespace Shamaseen\Repository\Generator\Utility;
10
11
use Illuminate\Contracts\Validation\Validator;
12
use Illuminate\Foundation\Http\FormRequest;
13
use Illuminate\Http\Exceptions\HttpResponseException;
14
use Illuminate\Http\JsonResponse;
15
use Illuminate\Validation\ValidationException;
16
17
/**
18
 * Class BaseRequests
19
 * @package App\Http\Requests
20
 */
21
class Request extends FormRequest
22
{
23
24
    /**
25
     * @param Validator $validator
26
     *
27
     * @throws HttpResponseException
28
     */
29
    protected function failedValidation(Validator $validator)
30
    {
31
32
        if (strpos($this->path(),'api') !== false) {
33
            $errors = (new ValidationException($validator))->errors();
34
            throw new HttpResponseException(response()->json(['success' => false, 'errors' => $errors,
35
            ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY));
36
        }
37
    }
38
39
    public function rules(){
40
        \App::setLocale($this->header('Language','en'));
41
    }
42
}
43