I am stuck in an authentication loop, and for the life of me cannot understand why.
Route::get('/', function()
{
return View::make('hello');
//return 'Hello ' . Auth::user()->first_name . '!';
});
Route::get('/login', function() {
return View::make('login');
});
Route::post('/login', function() {
// @TODO: Validate the login details!
Auth::attempt(array(
'email' => Input::get('email'),
'password' => Input::get('password')
));
return Redirect::to('/');
});
Route::group(array('before' => 'auth'), function() {
Route::get('/home', function()
{
//return View::make('hello');
return 'Hello ' . Auth::user()->first_name . '!';
});
/*
|--------------------------------------------------------------------------
| API Route Handlers
|--------------------------------------------------------------------------
|
| The API Routes.
|
*/
Route::group(array('prefix' => 'api/v1'), function() {
Route::resource('events', 'EventsController');
});
});
Here is the sequence of events:
I go to localhost:8000/home
it works and redirects me to /login
.
I then move on to log in.
It redirects me to the /
if I then go to /home
it still takes me to /login
Ideal case:
Go to /home
only to be redirected to /login
I log in then.
It redirects me to /
I can then move freely between /
and /home
without the worry of logging in.
EDIT 1
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->string('password');
$table->string('first_name');
$table->string('last_name');
$table->string('id_number')->unique();
$table->enum('user_type', array('option 1', 'option 2', 'option 3'));
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}