Reputation:
Is it possible in laravel to call a collection using
$flights = App\Flight::all();
but getting all that match a query for example
$flights = App\Flight::all()->where('pilotID', flightCaptainId);
Upvotes: 0
Views: 146
Reputation: 1
You can use the filter() function
$flights = App\Flight::all(); $flights = $flights->filter(function($flight) use ($flightCaptainId) { return $flight->pilotID == $flightCaptainId; });
Upvotes: 0
Reputation: 7509
Use get()
$flights = App\Flight::where('pilotID', flightCaptainId)->get();
Upvotes: 2