32 lines
668 B
PHP
32 lines
668 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Post extends Model
|
|
{
|
|
use HasFactory;
|
|
protected $table = 'posts';
|
|
|
|
protected $fillable = [
|
|
'title',
|
|
'description',
|
|
'status_published',
|
|
'status',
|
|
'user_id'
|
|
];
|
|
|
|
// Nama fungsi harus dalam bentuk singular karena relasi many-to-one
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id', 'id');
|
|
}
|
|
|
|
public function categories()
|
|
{
|
|
return $this->belongsToMany(Category::class, 'post_categories', 'post_id', 'category_id');
|
|
}
|
|
}
|