Try with query builder
$messages = DB::table('messages')->orderBy('created_date', 'desc')->paginate(10);
Hello , I'm trying to paginate with eloquent but I am no been success .
If I paginate like this , It will works -
$messages = Messages::orderBy('created_at', 'desc')->paginate(10);
But if I try to get all the messages from a user and paginate it , like this -
$messages = $this->user->Messages->paginate(10);
It will not paginate , some one know a better way to do it ? Thanks
You have to do this $messages = $this->user->Messages()->paginate(10);.
Note the parentheses. $this->user->Messages() returns the relationship instance, which behave like a query builder, so you can select messages with paginate. $this->user->Messages is a collection of messages so it can't work.
Please or to participate in this conversation.