/
StoreArticlesWithRelationship.php
54 lines (47 loc) · 1.21 KB
/
StoreArticlesWithRelationship.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
<?php
namespace App\Http\Requests\Admin\ArticlesWithRelationship;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
class StoreArticlesWithRelationship extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return Gate::allows('admin.articles-with-relationship.create');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => ['required', 'string'],
'perex' => ['nullable', 'string'],
'published_at' => ['nullable', 'date'],
'enabled' => ['required', 'boolean'],
'author' => ['required'],
'tags' => ['required']
];
}
public function getAuthorId()
{
if ($this->has('author')) {
return $this->get('author')['id'];
}
return null;
}
public function getTags(): array
{
if ($this->has('tags')) {
$tags = $this->get('tags');
return array_column($tags, 'id');
}
return [];
}
}