Passed
Push — master ( ab2678...bf154d )
by webdevetc
14:17
created

Category::edit_url()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace WebDevEtc\BlogEtc\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
7
8
class Category extends Model
9
{
10
    public $fillable = [
11
        'category_name',
12
        'slug',
13
        'category_description',
14
    ];
15
16
    protected $table = 'blog_etc_categories';
17
18
    /**
19
     * @return BelongsToMany
20
     */
21
    public function posts(): BelongsToMany
22
    {
23
        return $this->belongsToMany(
24
            Post::class,
25
            'blog_etc_post_categories',
26
            'blog_etc_category_id',
27
            'blog_etc_post_id'
28
        );
29
    }
30
31
    /**
32
     * Returns the public facing URL of showing blog posts in this category.
33
     *
34
     * @return string
35
     */
36
    public function url(): string
37
    {
38
        return route('blogetc.view_category', $this->slug);
39
    }
40
41
    /**
42
     * @deprecated - use editUrl()
43
     */
44
    public function edit_url(): string
45
    {
46
        return $this->editUrl();
47
    }
48
49
    /**
50
     * Returns the URL for an admin user to edit this category.
51
     */
52
    public function editUrl(): string
53
    {
54
        return route('blogetc.admin.categories.edit_category', $this->id);
55
    }
56
}
57