livewire throws an error when using paginated data

$posts should not be declared as a property in the Livewire component class, you passed the posts with the laravel view() helpers as data.

Remove the line

public $posts;

And replace $this->posts by $posts in the render function:

    public function render()
    {
        if($this->type == 'all')
            $posts = Post::latest()->paginate(5);
        else if($this->type == 'user')
            $posts = Post::where('user_id',Auth::id())->latest()->paginate(5);
        return view('livewire.user-posts', ['posts' => $posts]);
    }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top