I'm new to Laravel and ORMs in general, so this is probably a very basic concept that I'm missing. I have three tables that I'm trying to define a relation with using Laravel 4's Eloquent ORM. Here's the slimmed-down table definitions:
stores
id (PK)
name
postal_codes
id (PK)
postal_code
city
state
country
locations
id (PK)
store_id (FK => stores.id)
postal_code_id (FK => postal_codes.id)
*additional location-specific fields such as address, phone #, etc
The stores
table has a one to many relationship with the locations
table, so I can use $this->hasMany("Location")
in the Stores model, and $this->belongsTo("Store")
in the Location model.
My question is, how do I define the relation between locations
and postal_codes
in their respective models? The locations
table has a many-to-one relationship with the postal_codes
table. Ideally I want to be able to do something like this: $store->locations()->first()->city
. Is this possible?