-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTagUpdateRequest.php
63 lines (53 loc) · 1.51 KB
/
TagUpdateRequest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace App\Http\Requests;
use App\Rules\EachIsUnique;
use App\Student;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class TagUpdateRequest extends FormRequest
{
public $tag_types = [];
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$this->tag_types[] = "App\\Profile";
$locale = app()->getLocale();
foreach (Student::participatingSchools() as $shortname => $name) {
$this->tag_types[]= "App\\Student\\{$shortname}";
}
return [
'type' => [
'required',
'string',
Rule::in($this->tag_types),
],
'name' => [
'required',
'string',
'max:100',
(new EachIsUnique('/\r\n|\r|\n/', 'tags', 'name->'.$locale, ['type', $this->input('type')]))
->ignore($this->route()->parameters['tag'] ?? null),
],
];
}
public function messages()
{
$types_allowed = implode(', ', $this->tag_types);
return [
'type.in' => "The tag types allowed are: {$types_allowed}",
];
}
}