Completed
Push — master ( 2ccb51...4b9a6b )
by ARCANEDEV
02:56
created

Category::setNameAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php namespace Arcanesoft\Blog\Models;
2
3
use Arcanesoft\Blog\Bases\Model;
4
use Illuminate\Database\Eloquent\SoftDeletes;
5
6
/**
7
 * Class     Category
8
 *
9
 * @package  Arcanesoft\Blog\Models
10
 * @author   ARCANEDEV <[email protected]>
11
 *
12
 * @property  int             id
13
 * @property  string          name
14
 * @property  string          slug
15
 * @property  \Carbon\Carbon  created_at
16
 * @property  \Carbon\Carbon  updated_at
17
 * @property  \Carbon\Carbon  deleted_at
18
 */
19
class Category extends Model
20
{
21
    /* ------------------------------------------------------------------------------------------------
22
     |  Traits
23
     | ------------------------------------------------------------------------------------------------
24
     */
25
    use SoftDeletes;
26
27
    /* ------------------------------------------------------------------------------------------------
28
     |  Properties
29
     | ------------------------------------------------------------------------------------------------
30
     */
31
    /**
32
     * The database table used by the model
33
     *
34
     * @var string
35
     */
36
    protected $table    = 'categories';
37
38
    /**
39
     * The attributes that are mass assignable
40
     *
41
     * @var array
42
     */
43
    protected $fillable = ['name'];
44
45
    /**
46
     * Set or unset the timestamps for the model
47
     *
48
     * @var bool
49
     */
50
    public $timestamps  = true;
51
52
    /**
53
     * The attributes that should be mutated to dates.
54
     *
55
     * @var array
56
     */
57
    protected $dates    = ['deleted_at'];
58
59
    /* ------------------------------------------------------------------------------------------------
60
     |  Relationships
61
     | ------------------------------------------------------------------------------------------------
62
     */
63
    /**
64
     * Relationship with posts.
65
     *
66
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
67
     */
68
    public function posts()
69
    {
70
        return $this->hasMany(Post::class);
71
    }
72
73
    /* ------------------------------------------------------------------------------------------------
74
     |  Getters & Setters
75
     | ------------------------------------------------------------------------------------------------
76
     */
77
    /**
78
     * Set the name attribute.
79
     *
80
     * @param  string  $name
81
     */
82
    public function setNameAttribute($name)
83
    {
84
        $this->attributes['name'] = $name;
85
        $this->attributes['slug'] = str_slug($name);
86
    }
87
}
88