gpt4 book ai didi

php - 如何将数组传递给 laravel 中的 where 子句?

转载 作者:行者123 更新时间:2023-12-03 22:58:57 24 4
gpt4 key购买 nike

假设我有这个 ids 数组 [3,4,5] 我从 Eloquent 中得到它...

$route = Route::where('station_id',$stations_id)
->pluck('id')->toArray();

所以,我想在 where 子句中使用这个数组从每条路线获取每个时间表,我这样做了:

$schedule = Schedule::select('id')
->where('route_id',$route)
->get();

问题是这只显示一条路线的时间表 ID。

最佳答案

使用whereIn :

$schedule = Schedule::select('id')
->whereIn('route_id', $route)
->get();

关于php - 如何将数组传递给 laravel 中的 where 子句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57053179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com