Mikegk's avatar

Pre-rendering pagination view

Some people say that passing blank arrays to livewire and rendering them, is much faster than using objects due to serialization process. Sounds okay so far. The problem is, how would I get a pagination? I got used to this:

Livewire

//Livewire
$users = Users::where('display',true)->paginate(10)

Template

//HTML
@if($users->count())
	<div class="row">
			@foreach($users as $user)
					<div class="col-lg-6">
							{{$user->name}}
					</div>
			@endforeach
	</div>
	<div>{{$users->links()}}</div>
@endif

Is there a way to get the current html-pagination pre-rendered? Like

//Livewire
$users = Users::where('display',true)->paginate(10)
$pagination = $users->links()->render() //?!
$users = $users->toArray();
0 likes
4 replies
MichalOravec's avatar
Level 75

Try it like this:

$pagination = (string) $users->links();

or

$pagination = $users->links()->toHtml();
1 like
Mikegk's avatar

@MichalOravec Works awesome, thank you. For anyone who is interested in speed: This did not result in any better page speed. I don't know why (I also do not have 1:n queries or stuff thats slows laravel down) but on mobile devices with 3G the page is really, really slow. My old Codeigniter 2 and 3 stacks are responding so much faster... Of course I don't want to use CI... But for now I'm really desperated about how long a page load or ajax request takes...

Sinnbeck's avatar

@Mikegk I can suggest using either debugbar or clockwork to find out what might make it slow. Also be sure you have an index on "display" in the database

Also don't count records here

@if($users->isNotEmpty()) 
1 like

Please or to participate in this conversation.