В итоге запрос получился таким
select "channels".*,
(select "start" from "channel_program" where "channel_id" = "channels"."id" and "end" < '2019-07-02 06:10:21' order by "start" desc limit 1) as "start_time_show",
(select "start" from "channel_program" where "channel_id" = "channels"."id" and "start" <= '2019-07-02 06:10:21' and "end" > '2019-07-02 06:10:21' limit 1) as "start_time_current",
(select "start" from "channel_program" where "channel_id" = "channels"."id" and "start" > '2019-07-02 06:10:21' limit 1) as "start_time_notShow"
from "channels" where "channels"."deleted_at" is null
Сделал через scope
public function scopeScheduleShows($query)
{
$date = \Carbon\Carbon::now();
$query->addSubSelect('start_time_show', ChannelProgram::select('start')
->whereColumn('channel_id', 'channels.id')
->where('end','<', $date)
->latest('start')
)->with('show.program');
}
public function scopeScheduleCurrents($query)
{
$date = \Carbon\Carbon::now();
$query->addSubSelect('start_time_current', ChannelProgram::select('start')
->whereColumn('channel_id', 'channels.id')
->where('start','<=', $date)
->where('end','>', $date)
)->with('current.program');
}
public function scopeScheduleNotShows($query)
{
$date = \Carbon\Carbon::now();
$query->addSubSelect('start_time_notShow', ChannelProgram::select('start')
->whereColumn('channel_id', 'channels.id')
->where('start','>', $date)
)->with('notShow.program');
}
В контроллере вызываю так
Channel::scheduleShows()->scheduleCurrents()->scheduleNotShows()->paginate(10);
Подзапросы составить помогла эта статься
https://laravelnews.ru/dinamicheskie-otnosheniya-v... В ней описывается откуда берётся "addSubSelect".