|
1
|
|
|
<?php namespace Arcanesoft\Blog\Http\Requests\Admin\Posts; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanesoft\Blog\Http\Requests\Admin\FormRequest; |
|
4
|
|
|
use Arcanesoft\Blog\Models\Category; |
|
5
|
|
|
use Arcanesoft\Blog\Models\Post; |
|
6
|
|
|
use Arcanesoft\Blog\Models\Tag; |
|
7
|
|
|
use Illuminate\Validation\Rule; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class PostRequest |
|
11
|
|
|
* |
|
12
|
|
|
* @package Arcanesoft\Blog\Http\Requests\Admin\Posts |
|
13
|
|
|
* @author ARCANEDEV <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
abstract class PostRequest extends FormRequest |
|
16
|
|
|
{ |
|
17
|
|
|
/* ----------------------------------------------------------------- |
|
18
|
|
|
| Main Methods |
|
19
|
|
|
| ----------------------------------------------------------------- |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Get the validation rules that apply to the request. |
|
24
|
|
|
* |
|
25
|
|
|
* @return array |
|
26
|
|
|
*/ |
|
27
|
|
|
public function rules() |
|
28
|
|
|
{ |
|
29
|
|
|
// TODO: Adding seo rules |
|
30
|
|
|
return [ |
|
31
|
|
|
'title' => ['required', 'string', 'max:255'], |
|
32
|
|
|
'excerpt' => ['required', 'string', 'max:200'], |
|
33
|
|
|
'content' => ['required', 'string'], |
|
34
|
|
|
'category' => static::getCategoryRule(), |
|
35
|
|
|
'tags' => static::getTagsRule(), |
|
36
|
|
|
'published_at' => ['required', 'date_format:Y-m-d'], |
|
37
|
|
|
'status' => static::getPostStatusRule(), |
|
38
|
|
|
]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/* ----------------------------------------------------------------- |
|
42
|
|
|
| Other Methods |
|
43
|
|
|
| ----------------------------------------------------------------- |
|
44
|
|
|
*/ |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get the validated inputs. |
|
48
|
|
|
* |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getValidatedData() |
|
52
|
|
|
{ |
|
53
|
|
|
return array_merge([ |
|
54
|
|
|
'author_id' => $this->user()->getAuthIdentifier(), |
|
55
|
|
|
'category_id' => $this->get('category') |
|
56
|
|
|
], $this->only([ |
|
57
|
|
|
// POST inputs |
|
58
|
|
|
'title', 'excerpt', 'content', 'tags', 'published_at', 'status', |
|
59
|
|
|
|
|
60
|
|
|
// SEO inputs |
|
61
|
|
|
'seo_title', 'seo_description', 'seo_keywords', |
|
62
|
|
|
])); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Get the slug rule. |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $column |
|
69
|
|
|
* |
|
70
|
|
|
* @return \Illuminate\Validation\Rules\Unique |
|
71
|
|
|
*/ |
|
72
|
|
|
protected static function getSlugRule($column = 'slug') |
|
73
|
|
|
{ |
|
74
|
|
|
$prefix = config('arcanesoft.blog.database.prefix', 'blog_'); |
|
75
|
|
|
|
|
76
|
|
|
return Rule::unique("{$prefix}posts", $column); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get the category rule. |
|
81
|
|
|
* |
|
82
|
|
|
* @return array |
|
83
|
|
|
*/ |
|
84
|
|
|
protected static function getCategoryRule() |
|
85
|
|
|
{ |
|
86
|
|
|
return ['required', 'integer', 'in:'.Category::getSelectOptions(false)->keys()->implode(',')]; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get the tags rule. |
|
91
|
|
|
* |
|
92
|
|
|
* @return array |
|
93
|
|
|
*/ |
|
94
|
|
|
protected static function getTagsRule() |
|
95
|
|
|
{ |
|
96
|
|
|
return ['required', 'array', 'min:1', 'in:'.Tag::getSelectOptions()->keys()->implode(',')]; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Get the post status rule. |
|
101
|
|
|
* |
|
102
|
|
|
* @return array |
|
103
|
|
|
*/ |
|
104
|
|
|
protected static function getPostStatusRule() |
|
105
|
|
|
{ |
|
106
|
|
|
return ['required', 'string', 'in:'.Post::getStatuses()->keys()->implode(',')]; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|