Since you are within a namespace, you must use '\Validator' to reference the Validator component in the root namespace
In L5, $this->validate() from within a controller is considered a better practice
this
return Redirect::route('getCreate')->withErrors($validate)->withInput();
should be
..................->withErrors($validator).........
mnshankar said:
Since you are within a namespace, you must use '\Validator' to reference the Validator component in the root namespace
In L5, $this->validate() from within a controller is considered a better practice
It didn'work for me... or i'm doing it wrong!
i tried to put the use on top of the class but still the same error happen. I use this validation method because this is the one in the documentation and trying to learn the framework... if you know a good tutorial that show how to use with the $this->validate() i will be happy to check it :)
here is the code with the using! I replaced the $validate with $validator but it was not the error in the call stack.
but still i have my error :( What is wrong with it !! :(
if you guys can help please!
<?php namespace App\Http\Controllers;
use Illuminate\Validation;
use Illuminate\Support\Facades\Redirect;
class UserController extends Controller
{
public function getCreate()
{
return view('user.register');
}
public function postCreate()
{
$validator = Validator::make(Input::all(), array(
'username' => 'required|unique:users|min:4',
'pass1' => 'required|min:6',
'pass2' => 'required|same:pass1',
));
if ($validator->fails())
{
return Redirect::route('getCreate')->withErrors($validator)->withInput();
}
else
{
$user = User::Create(array(
'username' => Input::get('username'),
'password' => Hash::make(Input::get('password'))
));
if ($user)
{
return Redirect::route('home')->with('success', 'You registered successfully. You can now login.');
}
else
{
return Redirect::route('home')->with('fail', 'An error occured while creating the user. Please try again.');
}
}
}
}
trying this when i come back to home!
I hope that is the right answer! :D
i was reading by the time about the Request but didnt try it yet !
I would recommend that you use L5's built-in form requests and get it instantly validated even before it's passed to your controller! http://mattstauffer.co/blog/laravel-5.0-form-requests
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community