首页 >php教程 >PHP源码 >laravel Validator实例

laravel Validator实例

PHP中文网
PHP中文网原创
2016-05-23 08:39:091495浏览

php代码

public function getIndex()
    {
        $rules = array(
            'email' => 'required|email',
            'name' => 'required|between:1,20',
            'password' => 'required|min:8',
        );
        $message = array(
            "required"             => ":attribute 不能为空",
            "between"      => ":attribute 长度必须在 :min 和 :max 之间"
        );

        $attributes = array(
            "email" => '电子邮件',
            'name' => '用户名',
            'password' => '用户密码',
        );

        $validator = Validator::make(
            Input::all(), 
            $rules,
            $message,
            $attributes
        );
        if ($validator->fails()) {
            $warnings = $validator->messages();
            $show_warning = $warnings->first();
            return Response::Json(compact('show_warning'));
        }
        return Response::Json("ok");
    }




@if($errors->any())@foreach($errors->all() as $error){{ $error }}@endforeach@endif

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn