如何通过使用Laravel雄辩的Relatinoships获取数据 [英] How to fetch data by using Laravel Eloquent Relatinoships
问题描述
跳闸 - id(自动增量),trip_title,about_place,created_by
trips_album - id(auto_increment),trips_id(指向旅行表的id),album_status
album_images - album_id(指向id trip_album表),img_name
所以,现在我想要所有属于任何特定用户的专辑图片。我如何通过使用Laravel雄辩的关系来做到这一点。我正在使用Laravel 4.2。
第一个,你可以设置一些。
class Trip扩展Eloquent {
public $ table =tripps;
}
class Album Enloquent {
public $ table =trips_album;
}
class Image扩展Eloquent {
public $ table =album_images;
}
之后,使用有很多通过。文件此处
class Trip扩展Eloquent {
...
public function Images()
{
return $ this-> ; hasManyThrough('Image','Album','trip_id','album_id');
}
}
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');
}
}
这篇关于如何通过使用Laravel雄辩的Relatinoships获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!