This seems simple enough but I can't seem to figure it out.
I have the below Models
City -> HasMany Locations
Locations -> HasMany Restaurants
Restaurants -> BelongsTo Locations
This means that Restaurant is linked to City via Locations
Now I want to find Restaurants in a particular City based the Location provided but not restricted to just that location rather the City.
The values provided are the City name and Location name. So I can get the city_id and location_id
// this will get a city with all locations
$city = City::with('locations')->where('value', $c)->first();
$city_id = $city->id;
// this will get the location id
$location = Location::where('value', $l)->first();
$location_id = $location->id;
So my $restaurants query should find all restaurants where the location is part of the location of $city.
How can I achieve this?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1MSfSjZ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire