Completed
Push — add-user-settings ( 10fb12 )
by Fèvre
02:25
created

Article::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 Xetaravel\Models\Category;
5
use Xetaravel\Models\User;
6
use Xetaravel\Models\Scopes\DisplayScope;
7
use Eloquence\Behaviours\CountCache\Countable;
8
use Eloquence\Behaviours\Sluggable;
9
use Illuminate\Support\Facades\Route;
10
use Illuminate\Support\Facades\App;
11
12
class Article extends Model
13
{
14
    use Countable,
15
        Sluggable;
16
17
    /**
18
     * The "booting" method of the model.
19
     *
20
     * @return void
21
     */
22
    protected static function boot()
23
    {
24
        parent::boot();
25
26
        /**
27
         * The Route::getFacadeRoot() is undefined in the testing environment for mysterious reasons.
28
         */
29
        if (App::environment() != 'testing') {
30
            // Don't apply the scope to the admin part.
31
            if (Route::getFacadeRoot()->current()->getPrefix() != '/admin') {
32
                static::addGlobalScope(new DisplayScope);
33
            }
34
        } else {
35
            static::addGlobalScope(new DisplayScope);
36
        }
37
    }
38
39
    /**
40
     * Return the field to slug.
41
     *
42
     * @return string
43
     */
44
    public function slugStrategy(): string
45
    {
46
        return 'title';
47
    }
48
49
    /**
50
     * Return the count cache configuration.
51
     *
52
     * @return array
53
     */
54
    public function countCaches(): array
55
    {
56
        return [
57
            User::class,
58
            Category::class
59
        ];
60
    }
61
62
    /**
63
     * Get the category that owns the article.
64
     *
65
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
66
     */
67
    public function category()
68
    {
69
        return $this->belongsTo(Category::class);
70
    }
71
72
    /**
73
     * Get the user that owns the article.
74
     *
75
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
76
     */
77
    public function user()
78
    {
79
        return $this->belongsTo(User::class);
80
    }
81
82
    /**
83
     * Get the comments for the article.
84
     *
85
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
86
     */
87
    public function comments()
88
    {
89
        return $this->hasMany(Comment::class);
90
    }
91
}
92