Reputation: 870
I have set a route in my Laravel project, if it was with href I would have done it like this {{route('destination'),$country_from,$country_to}}
but now I want to pass in the form data as the $country_from
and $country_to
please how can I do this
<form action="{{route('destination')}}">
@csrf
<input type="text"
class="search-form flexdatalist"
name="origin"
placeholder="country_from"
data-search-in='name'
data-min-length='1'
/>
<img src="{{URL::asset('img/location.svg')}}" class="search-icon origin" width="28px" height="21px"/>
</div>
<div class=" col-md-3 mx-0 px-0">
<input type="text"
class="search-form flexdatalist"
name="country_to"
data-search-in='name'
data-min-length='1'
placeholder="Travelling to"
/>
<img src="{{URL::asset('img/location.svg')}}" class="search-icon destination" width="28px" height="21px"/>
</div>
<div class="col-md-3 mx-0 px-0">
<input type="text"
class="search-form flexdatalist"
name="residence"
data-search-in='name'
data-min-length='1'
placeholder="Residing In"
/>
<img src="{{URL::asset('img/location.svg')}}" class="search-icon residence" width="28px" height="21px"/>
</div>
<div class="col-md-3 px-0">
<input type="submit" value="Search Visas" class="btn btn-primary search-btn"/>
</form>
Route
Route::get('/{country_from}/{country_to}', 'DestinationCountriesController@index')->name('destination');
Upvotes: 0
Views: 828
Reputation: 3869
I don't understand exactly what you want to do:
You want to redirect the user to the URL after form submit, and use form values in the redirection URL?
return redirect()->route('route_name', ['country_from' => $request->country_from, 'country_to' => $request->country_to])
You want to use URL values as input values, so on page load, inputs are filled with URL values?
$country_from
and $country_to
as you declared those variables with your route. You so have those variables in your controller, you can sanitize them, bind them to the returned view (eg: return view('view', $data)
or return view('view', compact('country_from', 'country_to'))
), and accessed it as usual in your blade.\Request::route('country_from')
. You should sanitize this values before using it as input. value
attributes, or placeholder
, anywhere {{$country_to}}
.Upvotes: 1