I am having difficulty using sessions. In my projects both guests and users are able to search the site for tickets. If they are logged in users they are then taken straight through to a checkout with the ticket information transferred over the session. For guest users however I redirect to a login/register page. I would like to persist the ticket information they have selected in the session so that once they have logged in or registered they can then be redirected to checkout.
I believe my problem is with redirecting the user after login/registration however any advice on this topic in general would be gladly received. Thanks in advance.
I have never done this, but maybe you can 'catch' the guest session before the registration progress begins and store it in a variable. When the registration is completed you can use that variable to create a new session for the user.
You can take a look in the file RegisterUsers.php. The function below handles the registration process.
public function register(Request $request)
{
$data = Session::get('data'); // retrieve the session data
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
Session::put('key', 'value'); // put the session back
return redirect($this->redirectPath());
}
if the user is not logged in, have the form post to an unrestricted page that saves the cart away in the session before redirecting to the actual checkout.
The middleware and registration can then do their stuff as required.
Once in the checkout, check if the session data exists, and if so use that, otherwise use the form data just posted by the logged in user.
Thanks for the responses. I will try them out. Snapey I am not very clear on what you mean could you possibly elaborate? At the moment I am saving the 'cart' to a session and that works fine my problem seems to be that when a new user registers the original session is lost...