49 lines
1.0 KiB
PHP
49 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Post extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'Post';
|
|
protected $primaryKey = 'PostId';
|
|
protected $fillable = [
|
|
'KategoriId',
|
|
'SubKategoriId',
|
|
'JudulPost',
|
|
'SlugPost',
|
|
'DescPost',
|
|
'ImagePost',
|
|
'IsPublish',
|
|
];
|
|
|
|
public function kategori()
|
|
{
|
|
return $this->belongsTo(Kategori::class, 'KategoriId', 'KategoriId');
|
|
}
|
|
|
|
public function subkategori()
|
|
{
|
|
return $this->belongsTo(SubKategori::class, 'SubKategoriId', 'SubKategoriId');
|
|
}
|
|
|
|
public function getFormattedPublishDateAttribute()
|
|
{
|
|
return \Carbon\Carbon::parse($this->created_at)->translatedFormat('d F Y');
|
|
}
|
|
|
|
// public static function boot()
|
|
// {
|
|
// parent::boot();
|
|
|
|
// static::creating(function ($post) {
|
|
// $post->SlugPost = Str::slug($post->JudulPost);
|
|
// });
|
|
// }
|
|
}
|