0

我正在使用laravelista 评论包为我的网站发表评论。

尝试创建评论时,POST 方法通过(可评论模型及其 id 正确引用),但未保存评论。

我知道正在调用相应的 store 方法,因为它正确重定向并将 #comment 附加到 url,但评论的 id() 不存在:

供应商\laravelista\comments\src\CommentController.php (69 - 71)

        $comment->save();

        return Redirect::to(URL::previous() . '#comment-' . $comment->getKey());

但重定向 url 看起来像:

http://127.0.0.1:8000/test#comment-

因此,我在调用 save() 的行上方出现 error_log($comment),并在终端中获取:

{"commenter_id":1,
"commenter_type":"App\\Models\\User",
"commentable_id":25,
"commentable_type":"App\\Models\\Discussion", 
"comment":"test comment",
"approved":true,
"commenter":{"id":1,"name":"a", [other columns in user model]},
"commentable":{"id":25, [other columns in this model]}}

因此,模型实例肯定正在创建,但 save() 函数不起作用。

当我

error_log($comment->save());

它返回一个1,表示成功

我尝试在修补程序中复制它:

>>> use Laravelista\Comments\Comment;
>>> $comment = new Comment;
=> Laravelista\Comments\Comment {#3585}
>>> $comment->comment = "tinker";
=> "tinker"
>>> echo($comment);
{"comment":"tinker"}⏎
>>> $comment->save();
=> true
>>>

但是数据库中也没有任何内容。

如果有人能够指出我正确的方向,将不胜感激。

4

0 回答 0