php - Laravel 5. How I can save and take back values of Session -
i try save after log in of user, values in session database. try use code validate login , put in session.
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: use controller execute login. route defined code in down.
route::post('/new/login',['as' => 'authregister', 'uses' => 'usercontroller@login',function () { return response::json(['fail' => true], 404); }] );
after login validation, laravel did save line in database.
he doesn't save user_id. how can save information? other problem how can take informations of session ? in method tried use $request->session()->get('usuarios'), returned null.
var_dump($user) =
yes. see 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) "thiagothgb@gmail.com" ["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) "thiagothgb@gmail.com" ["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) }
try this, , check whether session values or not.
$user = model\account::where('username',$request['username'])->first(); $request->session()->put('usuarios',$user->toarray()); echo "<pre>"; print_r($request->session()->get('usuarios')); echo "</pre>"; die();
show me results
Comments
Post a Comment