Reputation: 49
How can i use the orderBy method with this script:
public function getProposalByUser($userId)
{
return ProposalModel::where('user_id', '=', $userId)->paginate(4)->orderBy('desc');
}
the script is to select the proposal where user have. and i want to arrange it for the top is newest. Thanks in advance, and sorry for my bad english..
Upvotes: 0
Views: 2115
Reputation: 41820
It seems the main problem is that you have used the methods in the wrong order.
public function getProposalByUser($userId)
{
return ProposalModel::where('user_id', '=', $userId)->orderBy('desc')->paginate(4);
}
paginate
actually returns the query results in a collection, and the collection doesn't have an orderBy
method, so you can't chain it like you can with the other query builder methods.
Secondly, it looks like the orderBy method needs another argument, unless your entity actually does have a property called 'desc'
.
Upvotes: 3
Reputation: 5092
Try this:
return ProposalModel::where('user_id', '=', $userId)->orderBy('created_date', 'desc')->paginate(4);
Upvotes: 0
Reputation: 1297
Try this:
return ProposalModel::where('user_id', '=', $userId)->orderBy('user_id', 'desc')->paginate(4);
Upvotes: 0