<form action="{!! route('country.store')" method='GET'>
{{ csrf_field() }} //Cant remember if this is correct... but double check
<select class="form-control" name="country_id" id="country_id">
<option value="0" disable="true" selected="true"> Select Country </option>
</select>
<select class="form-control" name="region_id" id="region_id">
<option value="0" disable="true" selected="true"> Select Region </option>
</select>
<select class="form-control" name="districts" id="districts">
<option value="0" disable="true" selected="true"> Select City </option>
</select>
<button type='submit'>Submit</button>
</form>
Controller
public function store( Request $request){
//First Note: You could use a custom request for validation (its a good idea)
//Do storage stuff
}
Otherwise, you would have to be more clear as to why you want to dynamically route based on user input... anything is possible, but the question is whether it is practical...
Hello , thank you so much for quick answer sir , my work consist on prompting the user about their location and save it in a session (store function ) so all the items they search for are in the location selected from that form and basically
public function store()
{
session()->put($country->name,$region->name,$city->name);
return redirect()->route('welcome.index', [$country, $region, $city]);
}
public function store(Request $request)
{
session()->put($request->only('country','region','city'));
return redirect()->route('welcome.index',$request->only('country','region','city'));
}
but you need to align everything because at the moment your fields are called country_id, region_id and districts
Thank you a lot for your answer , but it's still giving me : Missing required parameters for [Route: country.store] [URI: {country}/{region}/{city}], Error
The location data that's passed to the view are from this controller :
CountryController :
class CountryController extends Controller
{
public function countries(Request $request){
$countries = Country::all();
return view('welcome', compact('countries'));
}
public function regions(){
$countries_id = Input::get('country_id');
$regencies = Region::where('country_id', '=', $countries_id)->get();
return response()->json($regencies);
}
public function cities(){
$regions_id = Input::get('region_id');
$districts = City::where('region_id', '=', $regions_id)->get();
return response()->json($districts);
}
}