【发布时间】:2016-07-30 04:24:48
【问题描述】:
我有两张表 Songs (belongsTo App\Host) 和 Hosts (hasMany App\Song)。我的 Songs 表有一个 attempts 列,而我的 Host 表有一个 skip_threshold。我想查询出所有未达到其相关主机跳过阈值的歌曲。
我该怎么做?
我尝试过这样的事情:
return $songs = Song::whereIn('host_id', $available_hosts)
->where('attempts', '<', $songs->host->skip_threshold)->get();
我尝试使用 Eloquent 关系查询,但从测试中我发现这不起作用。我想尝试使用 Eloquent 来执行此操作,这样我就可以利用在刀片模板中预先加载相关数据的优势。
【问题讨论】:
标签: php mysql laravel eloquent