dpv46227 2014-10-28 03:13
浏览 66
已采纳

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

I am studying Laravel now and I have a problem with display validation messages in my page. Here's the error I have after clicking the submit button

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR) 
Class 'Validate' not found
----------------------------------------------
Open: C:\wamp\vhosts\flax_order\appoutes.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()) {

I put the validation process in my route. Here's my sample code.

Here's the form

@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>
.....

Here's my controller

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() 
    {

    }

Here's my 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');

                }

            }
        );

I don't know where did I go wrong. Can you help me with this? I am not so good in Laravel.

  • 写回答

1条回答 默认 最新

  • du7999 2014-10-28 03:21
    关注

    You are trying to use the laravel class which is validator not validate

    Thats what the error message is saying. That class does not exit. In short it giving you hint

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?