Fabrizio Fenoglio
Fabrizio Fenoglio

Reputation: 5947

How to get errors message with Laravel 4 using Ardent

I'm new to Laravel 4, and I took a look at Ardent. It seems to be a really good package for speed with validation. So I understand how to set the rules and insert data to my database but I still cannot find a way to display the error messages when the validations fail.

$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));

Upvotes: 1

Views: 1002

Answers (1)

mpj
mpj

Reputation: 5367

Just get rid of the ->Ardent segment:

$status = $comment->errors()->all();

Since Ardent extends Eloquent, you don't need to access it that way, all its functionality is in the original class. I guess that you are using that because you followed the package's documentation literally, but when it says

Retrieve all validation errors with Ardent->errors()->all(). Retrieve errors for a specific attribute using Ardent->validationErrors->get('attribute').

it really means that you should replace Ardent with your model instance.

Upvotes: 3

Related Questions