在Laravel验证过程中找不到“验证”类

时间:2014-10-28 03:13:12

标签: php validation laravel

我正在研究Laravel,我的页面中显示验证消息有问题。 这是我点击提交按钮后出现的错误

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR) 
Class 'Validate' not found
----------------------------------------------
Open: C:\wamp\vhosts\flax_order\app\routes.php
                    'lastname'      =>  'min:2|max:15',
                    'firstname'     =>  'min:2|max:20',
                    'middlename'    =>  'min:10|max:20',
                    'password'      =>  'required|min:8|max:30',
                    'cpassword'     =>  'required|same:password'
                );

                $validator = Validate::make(Input::all(), $rules);

                if($validator->fails()) {

我将验证过程放在我的路线中。 这是我的示例代码。

这是表格

@if ($error->has())

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

            @endif

<form action="{{ action('EmployeesController@handleRegister') }}" method="POST" role="form">

                <p class="required">Fields marked with (*) are required.</p>

                <div class="form-group">
                    <label>Employee Code: </label>
                    <input type="text" class="form-control tooltip_detail" name="emp_code" data-toggle="tooltip" value="" data-placement="top" title="{{ $instructions['code'] }}" />
                </div>
.....

这是我的控制器

public function register() 
    {

        $instructions = array(
                            'code'          => 'Ex: 0001',
                            'lastname'      => 'Ex: Peterson',
                            'firstname'     => 'Ex: Johlo',
                            'middlename'    => 'Ex: P.',
                            'password'      => 'Choose your password carefully',
                            'cpassword'     => 'Repeat your password'
                        );

        return View::make('register', array(
            'page_title'    => 'Flax: Food Ordering',
            'instructions'  => $instructions,
        ));

    }

    public function handleRegister() 
    {

    }

这是我的routes.php

Route::get('/','EmployeesController@index');
Route::get('/register', 'EmployeesController@register');
Route::get('/handleRegister', 'EmployeesController@handleRegister');

Route::post('/handleRegister', function() 
            {

                $rules = array(
                    'emp_code'      =>  'numeric|exists:employees',
                    'lastname'      =>  'min:2|max:15',
                    'firstname'     =>  'min:2|max:20',
                    'middlename'    =>  'min:10|max:20',
                    'password'      =>  'required|min:8|max:30',
                    'cpassword'     =>  'required|same:password'
                );

                $validator = Validate::make(Input::all(), $rules);

                if($validator->fails()) {

                    $messages = $validator->messages();

                    return Redirect::to('register')->withErrors($validator);

                } else {

                    fd('ok');

                }

            }
        );

我不知道哪里出错了。你能帮帮我吗?我在Laravel中不太好。

1 个答案:

答案 0 :(得分:1)

您正在尝试使用laravel而非validator

validate班级

这是错误消息的内容。那堂课没有退出。简而言之,它给你提示