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

Let's say i have this array of ids [3,4,5] which i get it from this Eloquent...

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

So, i wanted to use this array in where clause to get each schedule from each route and i did like this:

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

the problem is this showing the schedule ids of a one route only.

Use whereIn:

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

If you have an array where you want to fetch all those IDs, you can use whereIn(),

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

Though, that said - you could define a relation between the station routes and schedules by useing relations in Eloquent - this would make it rather easier to get all relational data, see the link below.

use whereIn

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

->whereIn in place of ->where

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