I'm new to Laravel. Currently trying to use eloquent in one of my application. I've 3 database tables.. trips, trips_album, album_images. Table column are as follows..
trips - id(auto increment), trip_title, about_place, created_by
trips_album - id(auto_increment), trips_id(pointing to 'id' of trip table), album_status
album_images - album_id(pointing to 'id' of trip_album table), img_name
So, now i want all album images of trips, which belong to any particular user. How can i do this by using Laravel Eloquent Relationships. I'm using Laravel 4.2.
The first, you may setting somethings.
class Trip extends Eloquent {
public $table = "trips";
}
class Album extends Eloquent {
public $table = "trips_album";
}
class Image extends Eloquent {
public $table = "album_images";
}
After that, using "Has Many Through". Document Here
class Trip extends Eloquent {
...
public function Images()
{
return $this->hasManyThrough('Image', 'Album', 'trip_id', 'album_id');
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.