Home > php教程 > PHP源码 > body text

laravel Validator实例

PHP中文网
Release: 2016-05-23 08:39:09
Original
1486 people have browsed it

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
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template