Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

append the new parameter to the same the current url parameter in get form in laravel

Tags:

php

laravel

i have an url with parameter such as

http://localhost:8000/search_doctor_home?specialty_id=1

and I have a get form and I need the new parameter to the current parameters so it is going to be

http://localhost:8000/search_doctor_home?specialty_id=1&degree_srch=4

not

http://localhost:8000/search_doctor_home?degree_srch=4

and I tried the following methods but it does not work

   <form method="GET" action="{{ url()->full() }}">

and

  <form method="GET" action="{{ request()->fullUrlWithQuery(['degree_srch' => 4]) }}">
like image 697
Shady Hesham Avatar asked Nov 27 '25 02:11

Shady Hesham


1 Answers

You can get the current query array by request()->query(), and merge the new params with the query array and appends to the url:

request()->fullUrlWithQuery(array_merge(request()->query(), ['degree_srch' => 4]));

or

route('your_route_name', array_merge(request()->query(), ['degree_srch' => 4]));
like image 184
Wilson Avatar answered Nov 29 '25 15:11

Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!