LaravelBlog   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A author() 0 4 1
A category() 0 4 1
A getSlugOptions() 0 6 1
A getRouteKeyName() 0 4 1
A nextItem() 0 6 1
A previousItem() 0 6 1
1
<?php
2
3
namespace Retosteffen\LaravelBlog\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Spatie\Sluggable\HasSlug;
7
use Spatie\Sluggable\SlugOptions;
8
use Spatie\Tags\HasTags;
9
10
class LaravelBlog extends Model
11
{
12
    use HasSlug;
13
    use HasTags;
14
15
    protected $table = 'blogs';
16
17
    protected $guarded = ['user_id', 'slug', 'created_at', 'updated_at'];
18
19
    public function author()
20
    {
21
        return $this->belongsTo('App\User', 'user_id');
22
    }
23
24
    public function category()
25
    {
26
        return $this->belongsTo('Retosteffen\LaravelBlog\Models\Category', 'category_id');
27
    }
28
29
    public function getSlugOptions(): SlugOptions
30
    {
31
        return SlugOptions::create()
32
    ->generateSlugsFrom('title')
33
    ->saveSlugsTo('slug');
34
    }
35
36
    public function getRouteKeyName()
37
    {
38
        return 'slug';
39
    }
40
41
    public function nextItem()
42
    {
43
        $nextItem = self::where('published', '=', true)->where('published_at', '>', $this->published_at)->orderBy('published_at')->first();
44
45
        return $nextItem;
46
    }
47
48
    public function previousItem()
49
    {
50
        $previousItem = self::where('published', '=', true)->where('published_at', '<', $this->published_at)->orderBy('published_at')->first();
51
52
        return $previousItem;
53
    }
54
}
55