1

我是 Laravel 的新手,以下工作,但对我来说似乎不是很“Laravel” - 我只需要检测消息所指的验证规则(必需、电子邮件、唯一等):

@if ($errors->has('email'))
    {{ $errors->first('email') }}
    @if (strpos($errors->first('email'), 'has already been taken'))
        {{ HTML::link('password', 'Need a reminder?', array(), FALSE); }}
    @endif
@endif

有什么建议么?

谢谢

4

1 回答 1

1

在你的控制器中,会做这样的事情(取决于它的配置方式)

控制器

public function store()
{
    $validator = Validator::make(Input::all(), array(
                      'name' => 'Dayle',
                      'email' => 'required|min:5'
                   ));

    if ($validator->passes())
    {
         // Redirect to success page or something
    }

    return Redirect::back()
             ->withInput()
             ->withErrors($validator)
             ->withFailed($validator->failed())
}

那么在你看来

看法

@if ($errors->has('email'))
    The specific email rule that failed was: {{ $failed['email'] }}
@endif
于 2014-05-13T04:59:26.307 回答