Laravel + Inertia + Vuejs: Pagination
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Title: Understanding Laravel + Inertia + Vuejs Pagination Issues and Solutions
Introduction
Laravel is an immensely popular PHP framework that has made life easier for developers. One of the significant benefits it provides is its flawless integration with third-party libraries like InertiaJS, a progressive JavaScript framework for building single-page applications (SPAs) and Vue.js, a versatile frontend JS framework that makes building interactive UIs simpler. However, as you've encountered, paginating your Laravel + Inertia + Vuejs project can be challenging due to the error `Uncaught (in promise) TypeError: Cannot read property 'id' of null`. Let us dive into the issue and provide a solution.
Understanding Data Pagination
Pagination helps in efficiently loading and displaying large amounts of data, making your application more responsive and user friendly. Laravel provides an elegant way to paginate Eloquent models through the `paginate()` method. In the given example, you're trying to retrieve all items within a 15-item per page limit (`$items = Item::paginate(15)`) but are experiencing issues in passing it to your view with InertiaJS and Vuejs.
Issues Encountered
The issue occurs because the response from Eloquent contains an array of items objects that are not directly related to each other, i.e., they're not a parent-child relationship. This means you can't access properties like "id" on an object within your array as it is null, causing the error `Cannot read property 'id' of null`.
Solution: Using Collections for Pagination
To solve this issue and make your pagination work flawlessly with InertiaJS and Vuejs, you can use collections to group items. Laravel provides a handy Collections class that allows you to manipulate arrays in a more flexible manner while ensuring that each item has a defined relationship.
Here's how you can implement this approach:
1. Create a new collection from your Eloquent model array: `$items = collect($model->get())`
2. Paginate the new collection using Laravel's `paginate()` method: `$items = $items->paginate(15)`
3. Pass the paginated collection to InertiaJS and Vuejs in your view: `return Inertia::render('Rentals/Items', ['items' => $items])`
By using collections, you'll have a consistent object structure for each item and can safely access its properties without triggering the error. Moreover, it will make managing your data within Vuejs easier as well.
Conclusion
Implementing Laravel, InertiaJS, and Vuejs together is an excellent way to build modern, responsive web applications. However, certain issues may arise when paginating Eloquent models in Inertia + Vuejs. By understanding the underlying issue and applying appropriate solutions using collections, your application will function smoothly, providing a seamless user experience.