我正在尝试使用 Ardent 从刀片模板中的表单返回错误。这是我在控制器中使用的功能:
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);
}
我在模型中的热心规则:
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!',
);
我在刀片模板中调用的是:
@if ($errors->has())
@foreach ($errors->all() as $error)
<div class='bg-danger alert'>{{ $error }}</div>
@endforeach
@endif
每次我尝试将不应该验证的数据输入到表单中时,我都会收到错误Call to a member function has() on array
,它指的是$errors->has()
有人知道吗?干杯