Completed
Push — master ( 20b252...4d5a46 )
by ARCANEDEV
04:35
created

PostRequest::getSlugRule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 5
cp 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php namespace Arcanesoft\Blog\Http\Requests\Admin\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
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 Functions
19
     | ------------------------------------------------------------------------------------------------
20
     */
21
    /**
22
     * Get the validation rules that apply to the request.
23
     *
24
     * @return array
25
     */
26
    public function rules()
27
    {
28
        return [
29
            'title'        => 'required|max:255',
30
            'excerpt'      => 'required|max:200',
31
            'content'      => 'required',
32
            'category'     => static::getCategoryRule(),
33
            'tags'         => static::getTagsRule(),
34
            'publish_date' => 'required|date_format:Y-m-d',
35
            'status'       => static::getPostStatusRule(),
36
        ];
37
    }
38
39
    /* ------------------------------------------------------------------------------------------------
40
     |  Other Functions
41
     | ------------------------------------------------------------------------------------------------
42
     */
43
    /**
44
     * Get the slug rule.
45
     *
46
     * @return \Illuminate\Validation\Rules\Unique
47
     */
48
    protected static function getSlugRule($column = 'slug')
49
    {
50
        $prefix = config('arcanesoft.blog.database.prefix', 'blog_');
51
52
        return Rule::unique("{$prefix}posts", $column);
53
    }
54
55
    /**
56
     * Get the category rule.
57
     *
58
     * @return string
59
     */
60
    protected static function getCategoryRule()
61
    {
62
        return 'required|min:1|in:'.Category::getSelectOptions(false)->keys()->implode(',');
63
    }
64
65
    /**
66
     * Get the tags rule.
67
     *
68
     * @return string
69
     */
70
    protected static function getTagsRule()
71
    {
72
        return 'required|array|min:1|in:'.Tag::getSelectOptions()->keys()->implode(',');
73
    }
74
75
    /**
76
     * Get the post status rule.
77
     *
78
     * @return string
79
     */
80
    protected static function getPostStatusRule()
81
    {
82
        return 'required|in:'.PostStatus::keys()->implode(',');
83
    }
84
}
85