Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

saurabh799@gmail.com's avatar

Laravel 5.1 - Session and request both do not hold values

After using Laravel's Auth method I find that I am not able to get email in its session. Nor I am able to retrieve anything in the request object.

dd(Session::all()) returns below

array:5 [▼ "_token" => "xxTG9QCKEc6YIGfT9JWTafSjacJhph7QjyIDJU6v" "_previous" => array:1 [▶] "flash" => array:2 [▶] "email" => null "login_82e5d2c56bdd0811318f0cf078b78bfc" => 1 ]

And Log::info('In Welcome Controller - email id - ' .$request->email .' - '. $request->username . ' - ' . Session::get('email'));

Returns blank except Session::get('email') return null

This is the Welcome Controller which is displayed on Authentication.

''' class WelcomeController extends Controller {

/**
 * Display Welcome and the list of entries by user or ask him to create one.
 *
 * @return \Illuminate\Http\Response
 */
public function displayWelcome(Request $request)
{
        Log::info('In Welcome Controller - email id - ' .$request->email .' - '. $request->username . ' - ' . Session::get('email'));
    
        
        Log::info('In Welcome Controller - all in session - '. dd(Session::all()) );
        $email = $request->email;
        Session::put('email', $request->email);  // # User that is currently logged in
        Session::save();
    return view('pages.Welcome')->with("email",$email);
}

} '''

Routes php ''' Route::get('Welcome', ['as' => 'login','uses' =>'WelcomeController@displayWelcome']);

// Authentication routes... Route::get('auth/login', ['as' => 'auth/login','uses' =>'Auth\AuthController@getLogin']); Route::post('auth/login', ['as' => 'auth/login','uses' =>'Auth\AuthController@postLogin']); Route::get('auth/logout', ['as' => 'auth/logout','uses' =>'Auth\AuthController@getLogout']);

'''

My Auth Page

'''

namespace App\Http\Controllers\Auth;

use App\users;

use Validator; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ThrottlesLogins; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller { /* |-------------------------------------------------------------------------- | Registration & Login Controller |-------------------------------------------------------------------------- | | This controller handles the registration of new users, as well as the | authentication of existing users. By default, this controller uses | a simple trait to add these behaviors. Why don't you explore it? | */

use AuthenticatesAndRegistersUsers, ThrottlesLogins;

private $redirectTo = '/'; //protected $redirectPath = '/register'; protected $redirectPath = '/Welcome'; protected $loginPath = 'auth/login';

/**
 * Create a new authentication controller instance.
 *
 * @return void
 */
 
private $maxLoginAttempts = 10;


public function __construct()
{
    $this->middleware('guest', ['except' => 'getLogout']);
}

/**
 * Get a validator for an incoming registration request.
 *
 * @param  array  $data
 * @return \Illuminate\Contracts\Validation\Validator
 */
protected function validator(array $data)
{
        return Validator::make($data, [           
        'email' => 'required|email|max:50|unique:users',
        'password' => 'required|confirmed|min:6|max:255',
    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return User
 */
protected function create(array $data)
{
    return user::create([
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);
}

}

'''

0 likes
3 replies
saurabh799@gmail.com's avatar

But the value of email is null...how can i get that...

array:5 [▼ "_token" => "xxTG9QCKEc6YIGfT9JWTafSjacJhph7QjyIDJU6v" "_previous" => array:1 [▶] "flash" => array:2 [▶] "email" => null "login_82e5d2c56bdd0811318f0cf078b78bfc" => 1 ]

InaniELHoussain's avatar

use the session()->flash('key', 'value') or session()->has('key'), session()->get('key')

Please or to participate in this conversation.