Passed
Push — 5.0.0 ( f07a46...357374 )
by Fèvre
05:39
created

Article::slugStrategy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Models;
6
7
use Eloquence\Behaviours\CountCache\CountedBy;
8
use Eloquence\Behaviours\CountCache\HasCounts;
9
use Eloquence\Behaviours\HasSlugs;
10
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
11
use Illuminate\Database\Eloquent\Relations\BelongsTo;
12
use Illuminate\Database\Eloquent\Relations\HasMany;
13
use Spatie\MediaLibrary\HasMedia;
14
use Spatie\MediaLibrary\InteractsWithMedia;
15
use Spatie\MediaLibrary\MediaCollections\Models\Media;
16
use Xetaio\Mentions\Models\Traits\HasMentionsTrait;
17
use Xetaravel\Models\Presenters\ArticlePresenter;
18
use Xetaravel\Observers\ArticleObserver;
19
20
#[ObservedBy([ArticleObserver::class])]
21
class Article extends Model implements HasMedia
22
{
23
    use ArticlePresenter;
0 ignored issues
show
Bug introduced by
The trait Xetaravel\Models\Presenters\ArticlePresenter requires the property $slug which is not provided by Xetaravel\Models\Article.
Loading history...
24
    use HasMentionsTrait;
25
    use HasCounts;
26
    use HasSlugs;
27
    use InteractsWithMedia;
0 ignored issues
show
introduced by
The trait Spatie\MediaLibrary\InteractsWithMedia requires some properties which are not provided by Xetaravel\Models\Article: $fallbackPaths, $fallbackUrls, $mediaConversionRegistrations, $forceDeleting, $media, $collection_name
Loading history...
28
29
    /**
30
     * The attributes that are mass assignable.
31
     *
32
     * @var array
33
     */
34
    protected $fillable = [
35
        'title',
36
        'user_id',
37
        'category_id',
38
        'is_display',
39
        'content'
40
    ];
41
42
    /**
43
     * The accessors to append to the model's array form.
44
     *
45
     * @var array
46
     */
47
    protected $appends = [
48
        'article_url',
49
50
        // Media Model
51
        'article_banner'
52
    ];
53
54
    /**
55
     * Return the field to slug.
56
     *
57
     * @return string
58
     */
59
    public function slugStrategy(): string
60
    {
61
        return 'title';
62
    }
63
64
    /**
65
     * Register the related to the Model.
66
     *
67
     * @param Media|null $media
68
     *
69
     * @return void
70
     */
71
    public function registerMediaConversions(Media $media = null): void
72
    {
73
        $this->addMediaConversion('article.banner')
74
                ->width(870)
75
                ->height(350)
76
                ->keepOriginalImageFormat();
77
78
        $this->addMediaConversion('original')
79
                ->keepOriginalImageFormat();
80
    }
81
82
    /**
83
     * Get the category that owns the article.
84
     *
85
     * @return BelongsTo
86
     */
87
    #[CountedBy]
88
    public function category(): BelongsTo
89
    {
90
        return $this->belongsTo(Category::class);
91
    }
92
93
    /**
94
     * Get the user that owns the article.
95
     *
96
     * @return BelongsTo
97
     */
98
    #[CountedBy]
99
    public function user(): BelongsTo
100
    {
101
        return $this->belongsTo(User::class);
102
    }
103
104
    /**
105
     * Get the comments for the article.
106
     *
107
     * @return HasMany
108
     */
109
    public function comments(): HasMany
110
    {
111
        return $this->hasMany(Comment::class);
112
    }
113
}
114