1

I am making a redirect to homecontroller after user authenticates and set a auth token to session for use in the home controller as -

Controller 1

$secret = Crypt::encrypt($secret);
  Session::put('secret', $secret);
  Session::save();      
  return redirect()->action('loginController@homeRedirect');

Controller 2 -> homeRedirect

function homeRedirect(){
      dd(Session::all());
      if(Session::has('secret')){
        $secret = Session::get('secret');
        Session::forget('secret');

Here the dump comes blank array. nothing comes in the session, however if i test this dd(Session::all()) then it gives correct details.

Also I have tried as sending data using with('secret', $secret) but that is also returning a blank session.

My session.php file has following entry 'driver' => 'file', and the laravel version is 5.2.

EDIT

Also if I try like this -

function homeRedirect(Request $request){
  $ses = $request->session()->get('secret');
  dd($ses);

Then I get error stating Session store not set on request.

1 Answer 1

0

As you are using Laravel 5.2 , you should make sure you have set route for your loginController@homeRedirect in web middleware.

Your route should be defined in routes.php like so

Route::group(['middleware' => ['web']], function () {

    Route::get('/homeredirect','loginController@homeRedirect');
}

If it's defined this way:

Route::group(['middleware' => ['web']], function () {


}

Route::get('/homeredirect','loginController@homeRedirect');

it won't work

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.