StorePostRequest::postFillData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 13
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 17
rs 9.8333
1
<?php
2
3
namespace App\Http\Requests;
4
5
use Carbon\Carbon;
6
use Illuminate\Foundation\Http\FormRequest;
7
8
class StorePostRequest extends FormRequest
9
{
10
    /**
11
     * Determine if the user is authorized to make this request.
12
     *
13
     * @return bool
14
     */
15
    public function authorize()
16
    {
17
        return $this->user()->hasPermission('perms.writer');
18
    }
19
20
    /**
21
     * Get the validation rules that apply to the request.
22
     *
23
     * @return array
24
     */
25
    public function rules()
26
    {
27
        return [
28
            'title'             => 'required|max:255|unique:posts,id,'.$this->id,
29
            'subtitle'          => 'required',
30
            'content'           => 'required',
31
            'post_image'        => 'required',
32
            'meta_description'  => 'required|max:255',
33
            'is_draft'          => 'nullable',
34
            'author'            => 'required',
35
            'slug'              => 'required|unique:posts,id,'.$this->id,
36
            'publish_date'      => 'required',
37
            'publish_time'      => 'required',
38
            'layout'            => 'required',
39
        ];
40
    }
41
42
    /**
43
     * Return the fields and values to create a new post.
44
     *
45
     * @return array
46
     */
47
    public function postFillData()
48
    {
49
        $published_at = new Carbon(
50
            $this->publish_date.' '.$this->publish_time
51
        );
52
53
        return [
54
            'title'             => $this->title,
55
            'subtitle'          => $this->subtitle,
56
            'post_image'        => $this->post_image,
57
            'content_raw'       => $this->get('content'),
58
            'meta_description'  => $this->meta_description,
59
            'is_draft'          => (bool) $this->is_draft,
60
            'author'            => $this->author,
61
            'slug'              => $this->slug,
62
            'published_at'      => $published_at,
63
            'layout'            => $this->layout,
64
        ];
65
    }
66
}
67