for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Str;
class ForumTopic extends Model
{
use HasFactory;
protected $fillable = ['category_id', 'title', 'slug', 'content', 'created_by'];
protected $dates = ['created_at', 'updated_at'];
protected static function boot()
parent::boot();
static::creating(function ($topic) {
$topic->slug = Str::slug($topic->title);
});
}
public function category()
return $this->belongsTo(ForumCategory::class, 'category_id');
public function author()
return $this->belongsTo(User::class, 'created_by');
public function posts()
return $this->hasMany(ForumPost::class, 'topic_id')->with('author');