Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lukeboy_2002's avatar

Illuminate\Pagination\LengthAwarePaginator::$username

Hi,

I have a scorelist. I created a component for this. this is the code of my component:

and this is the blade file

the code above is functional. Now I want to make a livewire component with a pagination per user.

Livewire component:

It is almost the same code. Now I get the error: Undefined property: Illuminate\Pagination\LengthAwarePaginator::$username

0 likes
2 replies
LaryAI's avatar
Level 58

The error you're encountering, Undefined property: Illuminate\Pagination\LengthAwarePaginator::$username, is due to the fact that you're trying to access properties on a LengthAwarePaginator object, which is not how pagination works in Laravel.

When you use pagination, the paginate() method returns a LengthAwarePaginator instance, which is a collection of paginated items. You need to iterate over the paginated items to access individual properties.

Here's how you can modify your Livewire component to handle pagination correctly:

  1. Remove the loop in the mount method: You should not loop through users and paginate each one individually. Instead, you should paginate the entire query result.

  2. Modify the query to paginate the users: Use the paginate() method directly on the query that retrieves the users.

Here's the corrected Livewire component:

In your Blade view (livewire.team), you can now iterate over $scoreList and use the pagination links:

This setup will paginate the users and their scores correctly, and you can navigate through the pages using the pagination links. Adjust the number of items per page in the paginate() method as needed.

JussiMannisto's avatar

When you call ->paginate(1), you get a pagination object which contains a collection of items - in this case a single item. You need to call ->first() instead of ->paginate(1) to get the result row.

You're doing a separate database query for every user in your database. That'll be really slow, especially if you have a lot of users. I'd run the query in chunks, e.g. 500 users at a time:

$scoreData = [];

$users = User::role('member')->chunkById(500, function($users) use(&$scoreData) {
	$results = DB::table('users')
		...
		->whereIn('users.id', $users->pluck('id'))
		->groupBy('users.id')
		->get();

	$scoreData = array_merge($scoreData, $results->toArray());
});

You're grouping by users.id, so there will be a single result row per user ID.

Please or to participate in this conversation.