739 0 0 0
Last Updated : 2025-04-29 01:07:13
At this snippet I will teach you how to get laravel collection with your wanted records by using an array of IDs with default sorting and disabled sorting
If you have an array of IDs and want to get all records belongs to these IDs in laravel eloquent you can use 2 expressions like this :
First (Default collection sorting)
$finalRecords = Triple::find($recordsArray); // change records array to your array of IDs
$finalRecords = Triple::whereIn('id', $recordsArray)->get(); // change records array to your array of IDs
Second (without sorting or keep sorting of your array)
$finalRecords = Triple::whereIn('id', $recordsArray)->orderByRaw("field(id,".implode(',',$recordsArray).")")->get(); // change records array to your array