In my Blade file, there are two dropdowns, "Countries" and "Regions". I want the Regions dropdown only to display the values linked to the country selected in the "Countries" dropdown.
For that, I believe, I have to pass a variable for $countries
and $regions
in order to compact them and call the variables in the blade file.
This is what I currently have (which is totally wrong), but what should it be?
public function create()
{
$countries = Countries::orderBy('name')->get();
$regions = Regions::where('countries_id' == $countries('id'))->orderBy('name')->get();
return view('admin.cities.create', compact('regions', 'countries'));
}
I know that the $regions
variable part "where('countries_id' == $countries('id'))
" is incorrect, but I've tried multiple other ways, and still not able to figure it out.
Is this variable = model::where(foreign_key == parent_table ID)
possible?
All my relationships have been set up with Laravel Eloquent already.
Any assistance would be appreciated