Completed
Push — master ( 0d066b...b259c2 )
by Fèvre
13s
created

Category::slugStrategy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Xetaravel\Models;
3
4
use Eloquence\Behaviours\Sluggable;
5
6
class Category extends Model
7
{
8
    use Sluggable;
9
10
    /**
11
     * The "booting" method of the model.
12
     *
13
     * @return void
14
     */
15
    protected static function boot()
16
    {
17
        parent::boot();
18
19
        // Generated the slug before updating.
20
        static::updating(function ($model) {
21
            $model->generateSlug();
22
        });
23
    }
24
25
    /**
26
     * Return the field to slug.
27
     *
28
     * @return string
29
     */
30
    public function slugStrategy(): string
31
    {
32
        return 'title';
33
    }
34
35
    /**
36
     * Get the articles for the category.
37
     *
38
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
39
     */
40
    public function articles()
41
    {
42
        return $this->hasMany(Article::class);
43
    }
44
}
45