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