0
I am with the ids returned from an immense query to bring the posts with a search term... Already working bring the posts through the Model by the selected IDS but it always brings sorted by ID and what I need is to sort by date... In the huge query I did, I already bring the ID’s sorted correctly but how much I use the model to search for the IDS, it clutters and brings ordered by the ID... Example of the code:
$terms = explode(' ', Input::get('search'));
$results =
DB::select(
DB::raw($this->getSearchQuery($terms))
);
$postIds = [];
foreach ($results as $result) {
array_push($postIds, $result->id);
}
$posts = Post::find($postIds);
The problem is in the last line that instead of seeking the IDS in the order I report, it searches in the ordered by the ID...
You tried to order using
Post::find($postIds)->orderBy('data');
?– lucasvscn
Yes! The answer is just below... I ended up implementing in the hand... I saw in the github of the own one.
– Sallo Szrajbman