|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MedianetDev\BackpackForm\Http\Requests; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
|
6
|
|
|
|
|
7
|
|
|
class FormbuilderRequest extends FormRequest |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Determine if the user is authorized to make this request. |
|
11
|
|
|
* |
|
12
|
|
|
* @return bool |
|
13
|
|
|
*/ |
|
14
|
|
|
public function authorize() |
|
15
|
|
|
{ |
|
16
|
|
|
// only allow updates if the user is logged in |
|
17
|
|
|
return backpack_auth()->check(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Get the validation rules that apply to the request. |
|
22
|
|
|
* |
|
23
|
|
|
* @return array |
|
24
|
|
|
*/ |
|
25
|
|
|
public function rules() |
|
26
|
|
|
{ |
|
27
|
|
|
$locale = locale(); |
|
|
|
|
|
|
28
|
|
|
return [ |
|
29
|
|
|
$locale .'.title' => 'required|min:3|max:255', |
|
30
|
|
|
$locale .'.text_button' => 'required|min:1|max:255', |
|
31
|
|
|
'intro' => 'nullable', |
|
32
|
|
|
'form' => 'nullable', |
|
33
|
|
|
'mail_to' => 'required_if:by_mail,1|max:255', |
|
34
|
|
|
'field_mail_name' => 'required_if:copy_user,1|max:255', |
|
35
|
|
|
]; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get the validation attributes that apply to the request. |
|
40
|
|
|
* |
|
41
|
|
|
* @return array |
|
42
|
|
|
*/ |
|
43
|
|
|
public function attributes() |
|
44
|
|
|
{ |
|
45
|
|
|
$language = default_language(); |
|
|
|
|
|
|
46
|
|
|
$attributes[$language . '.title'] = __('medianet-dev.backpack-form::formbuilder.labels.title') . ' ' . trans('medianet-dev.backpack-form::formbuilder.common.in_langue') . ' ' . trans('medianet-dev.backpack-form::formbuilder.languages.' . $language); |
|
|
|
|
|
|
47
|
|
|
$attributes['intro'] =__('medianet-dev.backpack-form::formbuilder.labels.intro'); |
|
48
|
|
|
$attributes['form'] = __('medianet-dev.backpack-form::formbuilder.labels.form'); |
|
49
|
|
|
$attributes['text_button'] = __('medianet-dev.backpack-form::formbuilder.labels.text_button'); |
|
50
|
|
|
$attributes['mail_to'] = __('medianet-dev.backpack-form::formbuilder.labels.mail_to'); |
|
51
|
|
|
$attributes['by_mail'] = __('medianet-dev.backpack-form::formbuilder.labels.by_mail'); |
|
52
|
|
|
return $attributes; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get the validation messages that apply to the request. |
|
57
|
|
|
* |
|
58
|
|
|
* @return array |
|
59
|
|
|
*/ |
|
60
|
|
|
public function messages() |
|
61
|
|
|
{ |
|
62
|
|
|
|
|
63
|
|
|
return [ |
|
64
|
|
|
'mail_to.required_if' => __('medianet-dev.backpack-form::formbuilder.validations.mail_to'), |
|
65
|
|
|
'field_mail_name.required_if' => __('medianet-dev.backpack-form::formbuilder.validations.field_mail_name'), |
|
66
|
|
|
]; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|