Yes, it is possible to get the original URL from which a link was clicked. You can achieve this by passing the original URL as a query parameter in the link and then retrieving it in the controller using the Request object.
Here's an example:
In your view file, add the original URL as a query parameter in the link:
<a href="{{ route('other-route', ['origin' => url()->current()]) }}">Other Route</a>
In your web.php file, define the route with the origin parameter:
Route::get('/other-route', [SomeController::class, 'otherRouteAction'])->name('other-route');
In your controller method, retrieve the origin parameter from the Request object:
public function otherRouteAction(Request $request)
{
$origin = $request->query('origin');
// use the $origin variable as needed
}
Note: This solution assumes that the original URL is the current URL. If you need to get the URL of the previous page, you can use the referer header instead of passing it as a query parameter.