I have 4 tables. I want to implement a query in one table and get data from related tables.
In CakePHP we use contain, but in Laravel I have no idea.
- country,
- state
- cities,
- Places
Model code
class Country extends Model {
public function states() {
return $this->hasMany('App\State');
}
}
class State extends Model {
public function city() {
return $this->hasMany('App\City');
}
}
class City extends Model {
public function location() {
return $this->hasMany('App\Location');
}
}
class Location extends Model {
}
I need to make a request in the Country, and I also want to get the state
$country = Country::where('id',1);
$country->states
Similarly, but how can I get cities -> locationwith this. Do I need to make another request manually? In CakePHP we use contain, but in Laravel there is no such keyword or functionality for this?
source
share