it is easy with named routes:
Route::get('route_one/{id}', function($id) {
return redirect()->route('route_two', $id);
})->name('route_one');
Route::get('route_two/{id}', function($id) {
dd($id);
})->name('route_two');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
If I am currently on mysite/route_one/43 and there is a button that redirects to mysite/route_two.
How can I pass the value 43 to /route_two?
Edit: There is a button in route_one with <a href="/route_two/" ..
it is easy with named routes:
Route::get('route_one/{id}', function($id) {
return redirect()->route('route_two', $id);
})->name('route_one');
Route::get('route_two/{id}', function($id) {
dd($id);
})->name('route_two');
@Nakov thanks! But I think it won't work in my case, I edited the post with more code (I am using href), also, route_two already has its own id. should I just add another one /{id}/{redirected_from_id}?
@cooperino try this:
<a href="/route_two/{{ request('id') }}"
of course your parameter in the url should be named id for the above to work.
@cooperino What are you using ? laravel ? vue ? jquery ? js ? please share you code
If you are in laravel blade or controller .. you will need to name your second route :
Route::get('second_route', [Controller::class, 'method'])->name('second_route');
and then use it in the controller or the blade and pass the id as a query_string
route('second_route).'?id='.$id
let your second route accept parameters such id
Route::get('second_route/{id}', [Controller::class, 'method'])->name('second_route');
route('second_route, $id);
@ehab.aboshehab sorry, I mean Laravel, added some code
@cooperino what do you mean by i am in route_one ??? please share ur full code .. for better assistance
Inside your controller you can get the parameter and pass it down to your view and append it to the button / link
@jeroenrosendaal it's href="/route_two/{id} <- the id is not the id of route_one, route_two already has an id, should I just add href="/route_two/{id}/{redirected_from} or some sort?
href="/route_two/{id}/?redirected_from={route_one_id}"
What does your routes, controller and view file look like?
just pass it in query string
<a href="/route_two/67?from=45"
and then check for it in the controller
if($request->has('from') {
@Snapey thank you! I thought there is some Laravel way to do it, but this seem the most convenient way
@cooperino In this kind of logics you will need to use a package or library that supports UTM tracking ..
@cooperino you could make it part of the route, but then you would need to make it optional
obviously be aware that the user can mess about with it
personally i always use named routes so like
<a href="{{route('product.show',['id'=>$product->id, 'from'=>$original->id])}}">
the route function will make unexpected parameters part of the querystring
@ehab.aboshehab What do you mean? I tried using it like @snapey said and it's working. You mean it can cause issues?
@Snapey Then if I leave it the simple way as you showed above it should be fine then right? Unless I'd need a UTM tracking library which I'm not sure what it is (But it is actually working right now)
Please or to participate in this conversation.