ForumTopic   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 29
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A posts() 0 3 1
A author() 0 3 1
A category() 0 3 1
A boot() 0 6 1
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Factories\HasFactory;
6
use Illuminate\Database\Eloquent\Model;
7
use Str;
8
9
class ForumTopic extends Model
10
{
11
    use HasFactory;
12
13
    protected $fillable = ['category_id', 'title', 'slug', 'content', 'created_by'];
14
    protected $dates = ['created_at', 'updated_at'];
15
16
    protected static function boot()
17
    {
18
        parent::boot();
19
20
        static::creating(function ($topic) {
21
            $topic->slug = Str::slug($topic->title);
22
        });
23
    }
24
25
    public function category()
26
    {
27
        return $this->belongsTo(ForumCategory::class, 'category_id');
28
    }
29
30
    public function author()
31
    {
32
        return $this->belongsTo(User::class, 'created_by');
33
    }
34
35
    public function posts()
36
    {
37
        return $this->hasMany(ForumPost::class, 'topic_id')->with('author');
38
    }
39
}
40