$feedbacks is a array , you can't call orderBy() on a array .
Sep 2, 2015
6
Level 1
Call to a member function orderBy() on a non-object
I'm trying to order my selected feedbacks by latest first and only showing 5 but when trying to achieve this, I get the error mentioned in the title.
It's prob simply something ridiculous or stupid that i'm missing but what am I doing wrong?
This is my code:
public function index(Tnb $tnb)
{
$user = Auth::user();
$feedbacks = array();
foreach($user->tnbs as $tnb)
{
foreach($tnb->feedbacks as $feedback)
{
$feedbacks[] = $feedback;
}
}
dd($feedbacks->orderBy('created_at', 'DESC'));
return view('profile.index', compact('user', 'tnb', 'feedbacks'));
}
Level 52
You can try with collection :
collect($feedbacks)->sortByDesc('created_at')->take(5)
3 likes
Please or to participate in this conversation.