feat: tambah modul blog dengan resource Filament, halaman publik, dan PostSeeder
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Post extends Model
|
||||
{
|
||||
protected $fillable = ['title', 'slug', 'category', 'content', 'author_id', 'published_at'];
|
||||
|
||||
protected $casts = ['published_at' => 'datetime'];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (Post $post) {
|
||||
$post->slug ??= Str::slug($post->title);
|
||||
});
|
||||
}
|
||||
|
||||
public function author(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'author_id');
|
||||
}
|
||||
|
||||
public function scopePublished($query)
|
||||
{
|
||||
return $query->whereNotNull('published_at')->where('published_at', '<=', now());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user