Closed MrMooky closed 7 years ago
@MrMooky Could you show more detailed code block?
@a-komarev I have no working code, thus I'm asking. The following code does not support a pager:
That's the way a thread is called within the show-action, that automatically fetches the messages the thread it is containing:
$thread = Thread::findOrFail($id);
The code should be something like this:
$thread = DB::table('threads')->messages->simplePaginate(10);
But that does not work.
$thread = Thread::findOrFail($id);
$thread->messages()->simplePaginate(10);
Wouldn't this work?
I've tried the code you suggested. Did not throw an error instantly... but when adding the needed code to my blade file, I got
Method links does not exist.
That's my current blade code, as provided here.
@each('messenger.partials.messages', $thread->messages, 'message')
{{ $thread->messages->links() }}
Read about Laravel pagination in documentation, please.
$messages = $thread->messages()->paginate(10);
And use $messages
collection in your views instead of fetching messages from thread again.
Hello again. I tried to implement a pager for the messages (->paginate(10)) but that does not work. Is there any way to limit the messages output within the show-action?