Hello,
First post here hope to get some help.
I've tried googling now for last couple of hours, but no luck yet.
I'm following this tutorial on user authentication,
http://code.tutsplus.com/tutorials/authentication-with-laravel-4--net-35593
So i got stuck when trying to pass errors to the view, when the user tries to register.
Code:
public function postCreate()
{
$validator = Validator::make(Input::all(), User::$rules);
if ($validator->passes())
{
$user = new User;
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->save();
return Redirect::to('users/login')->with('message', 'Din användare är nu skapad.');
} else
{
/*
$messages = $validator->messages();
foreach ($messages->all() as $message)
{
print($message);
}
exit;
*/
return Redirect::to('users/register')->with('message', 'The following errors occurred')->withErrors($validator)->withInput();
}
}
So, if i enter wrong values in the fields, i return to the same page, but the errors doesn't show.
Code in register.blade.php:
No matter what i do, it won't work.
As you can see in the controller i have commented out a foreach loop that will print all the messages, and that works fine!
I have no idea why i can't see the errors in register.blade.php.
The next problem is csrf, that won't work at all, written like the tutorial. I get this error with Laravel in debug true,
Illuminate \ Session \ TokenMismatchException
Open: /var/www/laravel/app/filters.php
|
*/
Route::filter('csrf', function()
{
if (Session::token() !== Input::get('_token'))
{
throw new Illuminate\Session\TokenMismatchException;
}
});
So that doesn't work either.
I have this as well:
$this->beforeFilter('auth', array('only' => array('getDashboard')));
In my controller constructor, just like the tutorial. When i use that, and try to log in, i just return to the login page.
If i comment it out it works, i get redirected to dashboard.
So there seems to be something weird going on with the Sessions, or something. I hope there's someone who can save my day!
I noticed that the tutorial is quite old, if you guys have any other one's you prefer, feel free to post a link, preferably here on Laracasts