我是Laravel 4的新手,我看了一眼Ardent。这似乎是一个非常好的速度验证包。因此,我了解如何设置规则并将数据插入数据库,但当验证失败时,我仍然找不到显示错误消息的方法。
$comment = new Post_comment();
$comment->id_poster = Input::get('id_poster');
$comment->like = "ciao";
$comment->text = Input::get('text');
$comment->id_post = Input::get('post_id');
if ($comment->save()) {
$status = "success";
} else {
$status = $comment->Ardent->errors()->all(); // this not working
}
echo json_encode(array('status' => $status));
只需去掉->Ardent
段:
$status = $comment->errors()->all();
由于Ardent扩展了Eloquent,您不需要以这种方式访问它,它的所有功能都在原始类中。我想你之所以使用它,是因为你确实遵循了软件包的文档,但当它说时
使用Ardent->errors()->all()检索所有验证错误。检索使用的特定属性的错误Ardent->validationErrors->get('attribute')。
这实际上意味着您应该用您的模型实例替换Ardent
。