|
1
|
|
|
<?php namespace Arcanesoft\Blog\Http\Requests\Backend\Posts; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanesoft\Blog\Bases\FormRequest; |
|
4
|
|
|
use Arcanesoft\Blog\Entities\PostStatus; |
|
5
|
|
|
use Arcanesoft\Blog\Models\Category; |
|
6
|
|
|
use Arcanesoft\Blog\Models\Tag; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class UpdatePostRequest |
|
10
|
|
|
* |
|
11
|
|
|
* @package Arcanesoft\Blog\Http\Requests\Backend\Posts |
|
12
|
|
|
* @author ARCANEDEV <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class UpdatePostRequest extends FormRequest |
|
15
|
|
|
{ |
|
16
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
17
|
|
|
| Properties |
|
18
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
19
|
|
|
*/ |
|
20
|
|
|
/** |
|
21
|
|
|
* Category validation rules. |
|
22
|
|
|
* |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $rules = [ |
|
26
|
|
|
'title' => 'required|max:255', |
|
27
|
|
|
'excerpt' => 'required|max:200', |
|
28
|
|
|
'content' => 'required', |
|
29
|
|
|
'category' => 'required|min:1', |
|
30
|
|
|
'tags' => 'required|array|min:1', |
|
31
|
|
|
'publish_date' => 'required|date|date_format:Y-m-d', |
|
32
|
|
|
'status' => 'required', |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
36
|
|
|
| Main Functions |
|
37
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
38
|
|
|
*/ |
|
39
|
|
|
/** |
|
40
|
|
|
* Determine if the user is authorized to make this request. |
|
41
|
|
|
* |
|
42
|
|
|
* @return bool |
|
43
|
|
|
*/ |
|
44
|
|
|
public function authorize() |
|
45
|
|
|
{ |
|
46
|
|
|
return true; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get the validation rules that apply to the request. |
|
51
|
|
|
* |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
public function rules() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->updateRules($this->rules); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
60
|
|
|
| Other Functions |
|
61
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
62
|
|
|
*/ |
|
63
|
|
|
/** |
|
64
|
|
|
* Update request rules. |
|
65
|
|
|
* |
|
66
|
|
|
* @param array $rules |
|
67
|
|
|
* |
|
68
|
|
|
* @return array |
|
69
|
|
|
*/ |
|
70
|
|
|
private function updateRules(array $rules) |
|
71
|
|
|
{ |
|
72
|
|
|
$rules['category'] .= '|in:' . implode(',', array_keys(Category::getSelectOptions(false))); |
|
73
|
|
|
$rules['tags'] .= '|in:' . implode(',', array_keys(Tag::getSelectOptions())); |
|
74
|
|
|
$rules['status'] .= '|in:' . implode(',', PostStatus::keys()); |
|
75
|
|
|
|
|
76
|
|
|
return $rules; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|