Completed
Pull Request — master (#34)
by Fèvre
06:03 queued 03:09
created

DiscussCategory::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
c 0
b 0
f 0
rs 9.6666
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace Xetaravel\Models;
3
4
use Eloquence\Behaviours\Sluggable;
5
use Xetaravel\Models\Presenters\DiscussCategoryPresenter;
6
7 View Code Duplication
class DiscussCategory extends Model
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    use Sluggable,
10
        DiscussCategoryPresenter;
11
12
    /**
13
     * The accessors to append to the model's array form.
14
     *
15
     * @var array
16
     */
17
    protected $appends = [
18
        'category_url'
19
    ];
20
21
    /**
22
     * The "booting" method of the model.
23
     *
24
     * @return void
25
     */
26
    protected static function boot()
27
    {
28
        parent::boot();
29
30
        // Generated the slug before updating.
31
        static::updating(function ($model) {
32
            $model->generateSlug();
33
        });
34
    }
35
36
    /**
37
     * Return the field to slug.
38
     *
39
     * @return string
40
     */
41
    public function slugStrategy(): string
42
    {
43
        return 'title';
44
    }
45
46
    /**
47
     * Get the threads for the category.
48
     *
49
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
50
     */
51
    public function threads()
52
    {
53
        return $this->hasMany(DiscussThread::class);
54
    }
55
}
56