Completed
Push — master ( e03510...6bc787 )
by ARCANEDEV
9s
created

Meta::prepareAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
crap 1
1
<?php namespace Arcanedev\LaravelSeo\Models;
2
3
use Arcanedev\LaravelSeo\Seo;
4
use Illuminate\Support\Arr;
5
6
/**
7
 * Class     Meta
8
 *
9
 * @package  Arcanedev\LaravelSeo\Models
10
 * @author   ARCANEDEV <[email protected]>
11
 *
12
 * @property  int                                  id
13
 * @property  int                                  seoable_id
14
 * @property  string                               seoable_type
15
 * @property  string                               title
16
 * @property  string                               description
17
 * @property  \Illuminate\Support\Collection       keywords
18
 * @property  \Illuminate\Support\Collection       metas
19
 * @property  boolean                              noindex
20
 * @property  \Carbon\Carbon                       created_at
21
 * @property  \Carbon\Carbon                       updated_at
22
 *
23
 * @property  \Illuminate\Database\Eloquent\Model  seoable
24
 */
25
class Meta extends AbstractModel
26
{
27
    /* -----------------------------------------------------------------
28
     |  Properties
29
     | -----------------------------------------------------------------
30
     */
31
    /**
32
     * The attributes that are mass assignable.
33
     *
34
     * @var array
35
     */
36
    protected $fillable = ['title', 'description', 'keywords', 'metas', 'noindex'];
37
38
    /**
39
     * The attributes that should be casted to native types.
40
     *
41
     * @var array
42
     */
43
    protected $casts = [
44
        'id'         => 'integer',
45
        'seoable_id' => 'integer',
46
        'keywords'   => 'collection',
47
        'metas'      => 'collection',
48
        'noindex'    => 'boolean',
49
    ];
50
51
    /* -----------------------------------------------------------------
52
     |  Constructor
53
     | -----------------------------------------------------------------
54
     */
55
    /**
56
     * Meta constructor.
57
     *
58
     * @param  array  $attributes
59
     */
60 24
    public function __construct(array $attributes = [])
61
    {
62 24
        parent::__construct($attributes);
63
64 24
        $this->setTable(Seo::getConfig('metas.table', 'metas'));
65 24
    }
66
67
    /* -----------------------------------------------------------------
68
     |  Relationships
69
     | -----------------------------------------------------------------
70
     */
71
    /**
72
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
73
     */
74 6
    public function seoable()
75
    {
76 6
        return $this->morphTo();
77
    }
78
79
    /* -----------------------------------------------------------------
80
     |  Other Methods
81
     | -----------------------------------------------------------------
82
     */
83
    /**
84
     * Prepare the attributes.
85
     *
86
     * @param  array  $attributes
87
     *
88
     * @return array
89
     */
90 24
    public static function prepareAttributes(array $attributes)
91
    {
92
        return [
93 24
            'title'       => Arr::get($attributes, 'title'),
94 24
            'description' => Arr::get($attributes, 'description'),
95 24
            'keywords'    => Arr::get($attributes, 'keywords', []),
96 24
            'metas'       => Arr::get($attributes, 'metas', []),
97 24
            'noindex'     => Arr::get($attributes, 'noindex', false),
98 8
        ];
99
    }
100
}
101