Skip to content

Instantly share code, notes, and snippets.

Created November 20, 2023 15:53
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Optimized Load More Laravel livewire
@if ($loadMore)
@if ($offset == 0)
@foreach ($posts as $post)
<td>{{ $loop->iteration + $offset }}</td>
<td>{{ $post->title }}</td>
<td>{{ $post->description }}</td>
@livewire('post-list', ['loadMore' => false, 'offset' => $offset + $limit], key($offset))
<button wire:click="$set('loadMore',true)">Load More</button>
namespace App\Livewire;
use App\Models\Post;
use Livewire\Component;
class PostList extends Component
public $offset = 0;
public $limit = 10;
public $posts;
public $loadMore;
public function mount($loadMore = true, $offset = 0)
$this->loadMore = $loadMore;
$this->offset = $offset;
public function render()
if ($this->loadMore) {
$this->posts = Post::offset($this->offset)->limit($this->limit)->get();
return view('');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment