Deploy Backend / deploy (push) Successful in 2m41s
- blog_comments table + Comment model/factory; comments attach to the post,
public list shows approved rows only, public submission starts unapproved
- Admin moderation API: list/filter, approve, delete comments
- Public POST posts/{slug}/view and posts/{slug}/like toggle counters
- Route groups: comments throttled like the contact form, interactions at
60/min; comments resource exposed to the generic admin list
41 lines
745 B
PHP
41 lines
745 B
PHP
<?php
|
|
|
|
namespace App\Models\Blog;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Comment extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'blog_comments';
|
|
|
|
protected $fillable = [
|
|
'post_id',
|
|
'name',
|
|
'email',
|
|
'body',
|
|
'is_approved',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_approved' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function post()
|
|
{
|
|
return $this->belongsTo(Post::class);
|
|
}
|
|
|
|
/**
|
|
* Only comments that survived moderation are shown to readers.
|
|
*/
|
|
public function scopeApproved($query)
|
|
{
|
|
return $query->where('is_approved', true);
|
|
}
|
|
} |