【发布时间】:2013-07-04 03:00:42
【问题描述】:
我正在尝试制作一个电视节目表,其中显示每个频道的当前和下一个即将播出的节目。 我想做这样的事情:
<table class="table">
<thead>
<tr>
<th></th>
<th>Now Playing</th>
<th>Next Upcoming Show</th>
</tr>
</thead>
<tbody>
@foreach ($shows as $show)
<tr>
<td>
<strong>{{ $show->channel->name}}</strong></td>
<td><strong>{{ date('H:i', strtotime($show->now->start)) }}</strong>
{{ $show->now->title }}</td>
<td><strong>{{ date('H:i', strtotime($show->next->start)) }}</strong>
{{ $show->next->title }}</td>
</tr>
@endforeach
</tbody>
</table>
我现在正在播放的节目是这样的: $shows = Show::with('channel') ->where('start', 'where('end', '>', DB::raw('(NOW() + INTERVAL 15 SECOND)')) ->orderBy('start')->get();
我似乎无法在同一个查询中获得每个频道的下一个即将播出的节目。 如果我能为当前的节目做这样的事情会很酷:$show->now->start 和下一个节目:$show->next->start
有什么想法吗?
我的数据库:
Schema::create('channels', function(Blueprint $table) {
$table->increments('id');
$table->string('name', 200);
$table->timestamps();
});
Schema::create('shows', function(Blueprint $table) {
$table->increments('id');
$table->integer('channel_id');
$table->string('title', 255);
$table->text('description')->nullable();
$table->dateTime('start');
$table->dateTime('end');
});
【问题讨论】:
-
有关您的数据库结构的更多信息,甚至是您尝试生成的原始查询,肯定会有所帮助。
标签: laravel laravel-4 eloquent