I'm not sure if this is what you are after, but it sounds like a 'Has Many Through' relationship.
http://laravel.com/docs/4.2/eloquent#relationships
If you scroll down, just before polymorphics, you should see it.
Hope that helps.
Not sure if ive read that right, but surely your tables should be something like this:
Citys
- id
- title
- state_id
- anything else you want
States
- id
- title
- anything else you want
A city 'belongs to' a state. A state 'has Many' cities.
Thus:
$aState = State::find(1);
foreach($aState->cities as $city)
{
echo '<hr/>'.$city->title;
}
$aCity = City::find(1);
echo 'My state is '.$aCity->state->title;
Hope that helps. Mark as solved if it does!
Thank you. I had been working with relationships in Laravel earlier, but I think I must have been overthinking this. Laravel was just making it too easy !
matyhaty said: Hope that helps. Mark as solved if it does!
I'm trying ! And searching/googling...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community