My application doesn't want to go in my GameController.php getIndex() function. It does go in the group function , I tested this with dd('test') vardump. It goes in it until it bumps into the 'game' route then it just doesn't want to go in this route.
routes.php :
Route::group(array('before' => 'auth'), function()
{
//dd('test') , this worked
Route::get('/game', array('as' => 'game','uses' =>'GameController@getIndex'));
});
GameController.php :
class GameController extends BaseController {
public function getIndex()
{
//dd('test') , he didnt do this dump
$items = DB::table('tblItems_Users')->where('FK_user_id', '=', Auth::user()->PK_user_id)
->join('tblItems', 'FK_item_id', '=', 'PK_item_id')->where('is_checked', '=', 0)
->get();
$item = $items[array_rand($items)];
return View::make('game')->with('item', $item);
}
}
AuthenticationController.php :
class AuthenticationController extends Controller
{
//login methode voor de http-get login request --> loginformulier weergeven
public function getLogin()
{
return View::make('login');
}
//login methode voor de http-post login request, wanneer er op de submitknop 'inloggen' gedrukt w
public function postLogin()
{
//validation rules toevoegen, zodat er geen leeg inlogformulier gesubmit kan worden
$validationRules = array( 'username' => 'required',
'password' => 'required'); //email is verplicht, en moet volgens emailformaat //paswd is verplicht, en minimum 8karakters lang
//The first argument passed to the make method is the data under validation. The second argument is the validation rules that should be applied to the data.
$validator = Validator::make(Input::all(), $validationRules);
if ($validator->fails())
{
dd('validator fails');
return Redirect::route('login')->withErrors($validator)->withInput(Input::only('username'));
}
$inputUsername = Input::get('username');
$inputPassword = Input::get('password');
if (Auth::attempt(array('username' => $inputUsername, 'password' => $inputPassword)))
{
//dd('test') => this is working
return Redirect::intended('/game');
}
else
{
$users = DB::table('tblUsers')->lists('username');
if(in_array($inputUsername, $users))
{
return Redirect::route('login')->withErrors(array('Oops! The password you entered is incorrect.'));
}
else
{
$this->storeUser();
$this->postLogin();
}
}
}
public function getLogout()
{
Auth::logout();
return Redirect::route('getLogin')->with('logoutSuccessMessage', "You're succesfully signed out! See you next time!");
}
public function storeUser()
{
$rules = array( 'username' => 'required|max:100',
'password' => 'required|max:60');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
return Redirect::route('login')->withErrors($validator)->withInput(Input::only('username'));
}
else
{
$inputPassword = Input::get('password');
$hashedPassword = Hash::make($inputPassword);
$user = new User;
$user->username = Input::get('username');
$user->password = $hashedPassword;
$itemids = DB::table('tblItems')->lists('PK_item_id');
$user->save();
foreach($itemids as $itemid)
{
$user->items()->attach($itemid);
}
}
}
}
The goal is to go to the 'game' page when my user is logged in, this is the case because the Laravel session cookie is made (I checked) and I can access the route manually by typing 'http://localhost:8000/user/game'. I also am making a new user and then after it is made logging him in automatically in the AuthenticationController.php file. (maybe it is also needed to know that users and items are in a many to many relationship). I am always getting redirected to 'http://localhost:8000' and strangely this page is always empty.