我的应用程序不想进入我的GameController.php getIndex()
函数。它确实在组函数中,我使用dd('test')
vardump进行了测试。它进入它直到它碰到“游戏”路线然后它只是不想进入这条路线。
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);
}
}
}
}
目标是在我的用户登录时转到“游戏”页面,这是因为Laravel会话cookie已经完成(我已经检查过),我可以通过输入“{{3}”来手动访问路径}”。我也正在创建一个新用户,然后在AuthenticationController.php文件中自动登录。 (也许还需要知道用户和项目处于多对多的关系中)。我总是被重定向到“http://localhost:8000/user/game”,奇怪的是这个页面总是空的。
答案 0 :(得分:0)
我修复了它,似乎postLogin()方法里面有postlogin()方法。这导致了错误。我在AuthenticationController中更改了这些行并且它有效。
替换了这些行:
$this->postLogin();
用这些:
if (Auth::attempt(array('username' => $inputUsername, 'password' => $inputPassword)))
{
return Redirect::to('game');
}