Shady Hesham
Shady Hesham

Reputation: 55

append the new parameter to the same the current url parameter in get form in 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]) }}">

Upvotes: 3

Views: 1303

Answers (1)

Wilson
Wilson

Reputation: 825

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]));

Upvotes: 3

Related Questions