You know that 10 is the default pagination number in laravel application. But can change it by passing the parameter in the pagination method to get how many posts we need to fetch per page. If we do not pass any number then laravel will fetch 10 posts per page. But we can change this default pagination number.

So if you need to change the laravel default pagination size, then you can follow this tutorial. Here I will show laravel pagination default limit and how to change default pagination number in laravel.

laravel-change-default-pagination-limit

Let's see the example code of how to change default pagination limit in laravel. Just add the $perPage protected variable in a model like this:

app/Models/Post.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Post extends Model
{
    use HasFactory;
    
    protected $perPage = 10; //you can change it to change default pagination number

    public function comments() : HasMany
    {
        return $this->hasMany(Comment::class);
    }
}

 

Look at that, you can change the default pagination number by changing the $perPage variable size. 

 

Read also: Laravel Access Pagination Protected Property Example

 

Conclusion

Now we know how to solve laravel default pagination size. Hope this laravel pagination default limit tutorial will help you to get how to change default pagination number in laravel.