Passed
Pull Request — master (#92)
by Fèvre
13:40 queued 08:22
created

ShopCategory::slugStrategy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
namespace Xetaravel\Models;
3
4
use Eloquence\Behaviours\Sluggable;
5
use Xetaravel\Models\Presenters\ShopCategoryPresenter;
6
7
class ShopCategory extends Model
8
{
9
    use Sluggable,
0 ignored issues
show
Bug introduced by
The trait Xetaravel\Models\Presenters\ShopCategoryPresenter requires the property $slug which is not provided by Xetaravel\Models\ShopCategory.
Loading history...
10
        ShopCategoryPresenter;
11
12
    /**
13
     * The attributes that are mass assignable.
14
     *
15
     * @var array
16
     */
17
    protected $fillable = [
18
        'title',
19
        'description',
20
        'is_display'
21
    ];
22
23
    /**
24
     * The accessors to append to the model's array form.
25
     *
26
     * @var array
27
     */
28
    protected $appends = [
29
        'category_url'
30
    ];
31
32
    /**
33
     * The "booting" method of the model.
34
     *
35
     * @return void
36
     */
37
    protected static function boot(): void
38
    {
39
        parent::boot();
40
41
        // Generated the slug before updating.
42
        static::updating(function ($model) {
43
            $model->generateSlug();
44
        });
45
    }
46
47
    /**
48
     * Return the field to slug.
49
     *
50
     * @return string
51
     */
52
    public function slugStrategy(): string
53
    {
54
        return 'title';
55
    }
56
57
    /**
58
     * Get the shop items for the category.
59
     *
60
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
61
     */
62
    public function shopItems()
63
    {
64
        return $this->hasMany(ShopItem::class);
65
    }
66
}
67