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

Rretzko's avatar
Level 15

Property type not supported in Livewire for property...

Hi all - I'm trying to create a LengthAwarePaginator in livewire from an array. I've included the "use Livewire\WithPagination" and "use WithPagination" in my component. When the component loads, I get the error:

Property type not supported in Livewire for property: [{"current_page":1,"data":[{"id":94,"full_name_alpha":"Lastname, Firstname","descr":"Soprano I","class_of":"1983 (alum)","school_year_descr":"1982-83"},
...
"first_page_url":"http:\/\/127.0.0.1:8000\/ensemble\/students\/4?page=1","from":1,"last_page":3,"last_page_url":"http:\/\/127.0.0.1:8000\/ensemble\/students\/4?page=3","links":[{"url":null,"label":"« Previous","active":false},{"url":"http:\/\/127.0.0.1:8000\/ensemble\/students\/4?page=1","label":"1","active":true},{"url":"http:\/\/127.0.0.1:8000\/ensemble\/students\/4?page=2","label":"2","active":false},{"url":"http:\/\/127.0.0.1:8000\/ensemble\/students\/4?page=3","label":"3","active":false},{"url":"http:\/\/127.0.0.1:8000\/ensemble\/students\/4?page=2","label":"Next »","active":false}],"next_page_url":"http:\/\/127.0.0.1:8000\/ensemble\/students\/4?page=2","path":"http:\/\/127.0.0.1:8000\/ensemble\/students\/4","per_page":20,"prev_page_url":null,"to":20,"total":41}]

I'm using the following to create the LengthAwarePaginator

private function schoolEnsembleMembersPagination(): LengthAwarePaginator
    {
        //convert array into collection
        $collection = new Collection($this->members);

        // Define how many items we want to be visible in each page
        $perPage = 20;

        // The current page, defaulting to 1 if none is set, or if the provided value is invalid
        $currentPage = LengthAwarePaginator::resolveCurrentPage();

        // Slice the collection to get the items to display in the current page
        $currentPageItems = $collection->slice(($currentPage - 1) * $perPage, $perPage)->all();

        // Create our paginator and pass it to the view
        return new LengthAwarePaginator($currentPageItems, count($collection), $perPage, $currentPage, [
            'path' => LengthAwarePaginator::resolveCurrentPath(),
        ]);

    }

When I do a dump of $this-schoolEnsembleMembersPagination(), I get the expected result:

Illuminate\Pagination\LengthAwarePaginator {#2149 ▼ // app\Livewire\Teachers\Schools\SchoolEnsembleStudentComponent.php:81
  #items: 
Illuminate\Support
\
Collection {#2079 ▶}
  #perPage: 20
  #currentPage: 1
  #path: "http://127.0.0.1:8000/ensemble/students/4"
  #query: []
  #fragment: null
  #pageName: "page"
  +onEachSide: 3
  #options: array:1 [▶]
  #total: 41
  #lastPage: 3
}

I'd appreciate any help in understanding what is creating the error message. Thanks!

0 likes
2 replies
LaryAI's avatar
Level 58

It seems like you're trying to store a LengthAwarePaginator instance as a property of a Livewire component, which is not supported because Livewire tries to keep all properties in sync between the front-end and the back-end. Complex objects like LengthAwarePaginator cannot be serialized and sent to the front-end.

Instead of storing the paginator itself as a property, you should store the necessary data to construct the paginator when needed. Here's how you can modify your Livewire component to work with pagination:

use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;

class YourLivewireComponent extends Component
{
    use WithPagination;

    public $members; // Assuming this is an array of your data

    public function render()
    {
        return view('your-view', [
            'members' => $this->schoolEnsembleMembersPagination(),
        ]);
    }

    private function schoolEnsembleMembersPagination(): LengthAwarePaginator
    {
        // Convert array into collection
        $collection = collect($this->members);

        // Define how many items we want to be visible in each page
        $perPage = 20;

        // The current page, defaulting to 1 if none is set, or if the provided value is invalid
        $currentPage = $this->page; // This is provided by the WithPagination trait

        // Slice the collection to get the items to display in the current page
        $currentPageItems = $collection->slice(($currentPage - 1) * $perPage, $perPage)->values();

        // Create our paginator and pass it to the view
        return new LengthAwarePaginator($currentPageItems, count($collection), $perPage, $currentPage, [
            'path' => request()->url(),
            'query' => request()->query(),
        ]);
    }
}

In your Blade view, you can then use the pagination links as follows:

<div>
    @foreach($members as $member)
        {{-- Display your member data --}}
    @endforeach

    {{ $members->links() }}
</div>

Remember to replace 'your-view' with the actual name of your Blade view file and adjust the @foreach loop to display your member data accordingly.

By using the WithPagination trait, Livewire will handle the pagination state for you, and you don't need to store the paginator instance in a property. The render method will create a new paginator instance every time it's called, which is what you want for rendering the view.

Rretzko's avatar
Level 15

This did not work, but it led me to rethink my implementation which is now throwing a similar but different error. I will create a separate discussion thread for that issue.

Please or to participate in this conversation.