How to insert New comments?
htmldiz opened this issue · comments
- Corcel Version: latest
- Framework Name & Version: latest
- PHP Version: 7.4
- Database Driver & Version: latest
Description:
Hi. How to insert new comments for post? Or work with comments?
Steps To Reproduce:--
@htmldiz have you looked at the unit tests for comments or looked at the model?
@htmldiz this should get you going:
use Corcel\Model\Post as Post;
use Corcel\Model\Comment as Comment;
...
$post = Post::find(1);
$comment = new Comment();
$comment->comment_author = 'Author Name';
$comment->comment_author_email = 'test@test.com';
$comment->comment_author_url = 'test.com';
$comment->comment_author_IP = '1.2.3.4';
$comment->comment_content = 'test';
$comment->comment_approved = 0;
$comment->comment_agent = 'test';
$comment->comment_type = 'comment';
$comment->comment_parent = 0;
$comment->save();
$post->comments()->save($comment);
Take a look at the Wordpress Comment Class definition to learn more about the values.
Note that because currently there are no $fillable
fields on Corcel/Model/Comment
we cannot pass an array of values to Comment::create()
else you're presented with a mass assignment exception.