the*_*ets 4 laravel eloquent laravel-5.1
我有一个具有以下关系的Offer类:
class Offer extends Model
{
public function releases()
{
return $this->belongsToMany('App\Release');
}
}
Run Code Online (Sandbox Code Playgroud)
Release类具有以下关系:
class Release extends Model
{
public function artist()
{
return $this->belongsTo('App\Artist');
}
}
Run Code Online (Sandbox Code Playgroud)
什么是最简单的修改方式
App\Offer::with('releases')->get();
Run Code Online (Sandbox Code Playgroud)
为了在每个版本中获得艺术家信息?
Arj*_*ten 11
你可以这样做:
App\Offer::with('releases.artist')->get();
Run Code Online (Sandbox Code Playgroud)
您可以查看:http://laravel.com/docs/5.1/eloquent-relationships#querying-relations了解更多信息.
如果您有多个关联,可以通过执行以下操作来查询它们:
App\Offer::with(['releases.artist', 'releases.albums'])->get();
Run Code Online (Sandbox Code Playgroud)
当你向下滚动时,你会看到
// Retrieve all posts that have at least one comment with votes...
$posts = Post::has('comments.votes')->get();
Run Code Online (Sandbox Code Playgroud)
请记住,"点"符号是Laravel的标准惯例.例如,加载视图:
view('folder.viewfile');
Run Code Online (Sandbox Code Playgroud)
这同样适用于雄辩嵌套关系.
| 归档时间: |
|
| 查看次数: |
5999 次 |
| 最近记录: |