ForumTopic::author()   A
last analyzed

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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
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