commit | author | age
|
24347e
|
1 |
<?php |
D |
2 |
|
|
3 |
namespace App\Http\Requests; |
|
4 |
|
|
5 |
use App\Rules\KeysiteCheck; |
|
6 |
use Illuminate\Contracts\Validation\Validator; |
|
7 |
use Illuminate\Foundation\Http\FormRequest; |
|
8 |
use Illuminate\Http\Exceptions\HttpResponseException; |
|
9 |
use Illuminate\Validation\ValidationException; |
|
10 |
|
|
11 |
class genericPicasso extends FormRequest |
|
12 |
{ |
|
13 |
|
|
14 |
public function attributes() |
|
15 |
{ |
|
16 |
return [ |
|
17 |
'format' => 'formato', |
|
18 |
'k' => 'keysite', |
|
19 |
]; |
|
20 |
} |
|
21 |
|
|
22 |
/** |
|
23 |
* Determine if the user is authorized to make this request. |
|
24 |
* |
|
25 |
* @return bool |
|
26 |
*/ |
|
27 |
public function authorize() |
|
28 |
{ |
|
29 |
return true; |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* Get the validation rules that apply to the request. |
|
34 |
* |
|
35 |
* @return array<string, mixed> |
|
36 |
*/ |
|
37 |
public function rules() |
|
38 |
{ |
|
39 |
return [ |
|
40 |
'format' => 'in:xml,json', |
|
41 |
'k' => ['required', new KeysiteCheck( request()->headers->get('referer') )], |
|
42 |
]; |
|
43 |
} |
|
44 |
|
|
45 |
public function messages() |
|
46 |
{ |
|
47 |
return [ |
|
48 |
'required' => 'Il campo :attribute รจ obbligatorio', |
|
49 |
'in' => 'Il campo :attribute dev\'essere valorizzato con: :values', |
|
50 |
]; |
|
51 |
} |
|
52 |
|
|
53 |
protected function failedValidation(Validator $validator) |
|
54 |
{ |
|
55 |
$errors = (new ValidationException($validator))->errors(); |
|
56 |
throw new HttpResponseException( |
|
57 |
response($errors, 422) |
|
58 |
); |
|
59 |
} |
|
60 |
} |