セッションデータベースのユーザーのログイン後に保存しようとしています。私はこのコードを使ってログインを検証し、セッションに入れようとします。Laravel 5.セッションの値を保存して戻す方法
protected function login(Request $Request){
$var = $Request->session()->all();
return dd($var);
$user = Model\Account::where('username',$Request['username'])->first();
if(isset($user)){
if (Hash::check($Request['password'], $user->password))
{
$Request->Session()->put('usuarios',$user);
return view('aluno/showActivities');
}
else{
return dd('Invalid password.');
}
}
else{
return dd('User doesn't exists.');
}
}
OBS:私はログインを実行するためにコントローラを使用します。このルートは、コードのように定義されています。ログイン検証した後
Route::post('/new/login',['as' => 'authRegister', 'uses' => '[email protected]',function() {
return Response::json(['Fail' => true], 404);
}]);
、laravelは、データベースにこの行を保存しました。
彼はuser_idを保存しません。この情報をどのように保存できますか? その他の問題は、セッションの情報をどのように取り戻すことができるかです。 getメソッドでは、$ Request-> session() - > get( 'usuarios')を使用しようとしましたが、nullを返しました。
のvar_dump($ユーザー)=
yes. See the result.
object(App\Model\Account)#198 (23) { ["table":protected]=> string(7) "account" ["connection":protected]=> string(5) "mysql" ["fillable":protected]=> array(3) { [0]=> string(5) "email" [1]=> string(8) "password" [2]=> string(8) "username" } ["primaryKey":protected]=> string(2) "id" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(8) { ["id"]=> int(4) ["email"]=> string(20) "[email protected]" ["password"]=> string(60) "$2y$10$yFZDFHH2tr6OeoRtEShSmOsX99TQ7e.o5Tb2mJ7sA4tNZEXr4s3tG" ["username"]=> string(10) "thiagothgb" ["deleted_at"]=> NULL ["created_at"]=> string(19) "2016-04-23 17:20:10" ["updated_at"]=> string(19) "2016-04-23 17:20:10" ["user_id"]=> int(6) } ["original":protected]=> array(8) { ["id"]=> int(4) ["email"]=> string(20) "[email protected]" ["password"]=> string(60) "$2y$10$yFZDFHH2tr6OeoRtEShSmOsX99TQ7e.o5Tb2mJ7sA4tNZEXr4s3tG" ["username"]=> string(10) "thiagothgb" ["deleted_at"]=> NULL ["created_at"]=> string(19) "2016-04-23 17:20:10" ["updated_at"]=> string(19) "2016-04-23 17:20:10" ["user_id"]=> int(6) } ["relations":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["casts":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["morphClass":protected]=> NULL ["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false) }
あなたはこの変数 '$ user'をダンプして結果配列を表示できますか?ダンプ結果を質問 – Qazi
yesに追加してください。結果を参照してください。 –
私は尋ねている、結果を示す – Qazi