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

mozew's avatar
Level 6

Undefined property: Illuminate\Pagination\LengthAwarePaginator::Is there a way to replace it?

What is this error?

Undefined property: Illuminate\Pagination\LengthAwarePaginator::$user_id

ArticleController.php

public function index()
    {
        $schools_lists = SchoolsList::latest()->paginate(25);
        if(Auth::user()->id == $schools_lists->user_id){
            return view('Admin.submit-information.all', compact('schools_lists'));
        }
    }

Is there a way to replace $user_id?

0 likes
5 replies
jlrdw's avatar

Where are you assigning user_id, I see no request or parameter even being passed?

mozew's avatar
Level 6

This error occurred on the following line.

return view('Admin.submit-information.all', compact('schools_lists'));
AlexDemin's avatar

Here is your problem:

if(Auth::user()->id == $schools_lists->user_id){

$schools_lists is a collection of records, there is no user_id attribute.

Add where clause to your query to filter records by user_id. And get rid of that if statement...

AlexDemin's avatar
Level 15

Can you give me the code sample?

public function index()
    {
        $schools_lists = SchoolsList::where('user_id', Auth::user()->id)->latest()->paginate(25);
        return view('Admin.submit-information.all', compact('schools_lists '));
    }
1 like

Please or to participate in this conversation.