2

I'm using laravel 5.5 and I have below code in my controller:

function booking(Request $request)
{
    parse_str($request->getContent(), $info);
    Session::put('quotation.flight.passengerDetails', $info);       
    return Session::get('quotation.flight.searchType');
}

This is what i have my route (web.php):

 Route::post('ajax/flight/booking', 'Flight\flightController@booking');

This is my ajax

$.ajax({
    url: flagsUrl + "ajax/flight/booking",
    type: 'POST',
    data: opts.bookingData,
    contentType: "json",
    success: function (view) {    
        opts.callback(view);    
    },
    error: function (xhr, ajaxOptions, thrownError) {
        opts.callback("");
    }    
});

When I call the route through ajax using POST, the $info doesn't assigning to the quotation.flight.passengerDetails session.

But it does work when I do a request using reply XHR in Chrome Developer Tools?

14
  • need more info which variable is not being set ? Commented Mar 28, 2018 at 12:41
  • oh it's $info variable not assigning into 'quotation.flight.passengerDetails' session Commented Mar 28, 2018 at 12:43
  • Whats the error u receive Commented Mar 28, 2018 at 12:44
  • 1
    Where are you calling Session::save() on your execution plan? Commented Mar 28, 2018 at 12:50
  • 1
    In theory it shouldn't be mandatory. In practice, I found it resolved a LOT of the issues I had with sessions in laravel. What I usually do is make sure that ad the end of my own personal flow I call a Session::save() before outputting to the browser. Commented Mar 28, 2018 at 13:00

1 Answer 1

1

Try using Session::save() after you put() or push() variables in the session object.

Usually this makes sure that the save is called when not called by any other process.

Alternatively you can analyze your execution flow and add a Session::save() at the end of your output gathering, right before your script outputs to the user, whether it be ajax or html.

For example:

$kernel = $app->make('Illuminate\Contracts\Http\Kernel');
$response = $kernel->handle(
            $request = Illuminate\Http\Request::capture()
        );
\Session::save();
Sign up to request clarification or add additional context in comments.

1 Comment

It worked like a charm. Thanks a lot for the quick support.

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.