PHP code example of vitorf7 / lv-loadmorepagination

1. Go to this page and download the library: Download vitorf7/lv-loadmorepagination library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vitorf7 / lv-loadmorepagination example snippets




namespace App;

use VitorF7\LoadMorePagination\LoadMorePagination;

class Post extends Model
{
    use LoadMorePagination;
}

// in a controller action or something you can use it like so
Post::paginateLoadMore(); // Loads 9 on first page and 3 every page after that
Post::paginateLoadMore(8, 4); // Loads 8 on first page and 4 every page after that
Post::paginateLoadMore(4, 4); // Loads 4 on first page and 4 every page after that. However at this point you could just simply use Post::paginate(4). This package is better used when you need to load different amount of items from the first page

// You can use it after you do an eager load of relationship too. At least simple loads for now as it has not been tested with something more complex
Post::with('categories')->paginateLoadMore();



namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use VitorF7\LoadMorePagination\LoadMorePagination;

class PostsController extends Controller
{
    use LoadMorePagination;

    public function index()
    {
        $posts = $this->paginatedLoadMore(9, 3, new Post);

        return view('posts.index', compact('posts'));
    }
}