I'm trying to return the errors from a form in a blade template using Ardent. This is the function I'm using in my controller:
public function store()
{
$subscriber = new Subscriber;
$subscriber->first_name = Input::get('first_name');
$subscriber->last_name = Input::get('last_name');
$subscriber->email = Input::get('email');
if(!$subscriber->save())
{
return Redirect::to('/admin/subscriber/create')->with('errors', $subscriber->errors()->all());
}
return Redirect::to('/admin/subscriber')->with('status', 1);
}
My ardent rules in the model:
public static $rules = array(
'email' => 'required|email|unique:users',
'first_name' => 'required',
'last_name' => 'required',
);
public static $customMessages = array(
'first_name.required' => 'First name is required.',
'last_name.required' => 'Last name is required.',
'email.required' => 'Email is required.',
'email.email' => 'Use a real email address!',
'email.unique' => 'This email address already exists!',
);
And what I'm calling in my blade template:
@if ($errors->has())
@foreach ($errors->all() as $error)
<div class='bg-danger alert'>{{ $error }}</div>
@endforeach
@endif
Every time I try inputting data that should not validate into the form I get the error Call to a member function has() on array
which refers to the $errors->has()
Anybody have any idea? Cheers