Something like:
$post->save($comment);
Make everything fillable in your models:
for example:
protected $fillable = [
'user_id'
];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I am building a blog and I want to save comments and replies on a post by using Eloquent. I used proper relationships on all models. But now it is giving me error that user_id does not has a default value. So how do i add a comment on post by just passing comment-body parameter from request and filling post-id and user-id from eloquent automatically.
Please or to participate in this conversation.