You can try using a middleware for
You would add this middleware just to your login route (the POST one, which actually logs the user in, not the one which shows the view) save any data you need from the session before proceeding, and then merging the quotes if the login was successful.
Something like this:
<?php
namespace App\Http\Middleware;
use App\Models\User;
use Illuminate\Http\Request;
class MergeQuotes
{
public function handle(Request $request, \Closure $next)
{
// before procssing the request, we grab the current quotes
$quotes = $request->session()->get(/* ... */);
// we tell laravel to process the request
$response = $next($request);
// if the response is successful, and the request now
// has a user, we merge the quotes
if ($response->isSuccessful() && $request->user()) {
$this->mergeQuotes($request->user(), $quotes);
}
return $response;
}
private function mergeQuotes(User $user, $quotes)
{
// your quote merging logic goes here
}
}