【发布时间】:2019-10-24 07:06:52
【问题描述】:
我正在开发公交车站管理系统。我正在尝试在时间表中排队巴士。 所以我想要的是这个:
-
我想显示特定车站的所有巴士,这些巴士不在特定时间表的队列中。
- 就像一个车站有 5 辆巴士,那么其中两辆在特定时间表的队列中,我想将所有其他 3 辆巴士显示到队列中。
公交车表
站台表
所以我就这样做了
public function getBusQueue(Request $request)
{
$id = $request->id; // id of the targert schedule
// getting the target station id;
$schedule = Schedule::find($id);
$stations_id = $schedule->station_id;
// getting the buses that are not in queues table
$buses = DB::table("buses")->select('*')
->whereNotIn('bus_number',function($query) {
$query->select('bus_number')->from('queues');
})
->where('Schedule_id', $id)
->where('station_id', $stations_id)
->get();
$data = $buses;
return Response()->json($data);
}
【问题讨论】:
标签: mysql laravel eloquent query-builder laravel-query-builder