bradtraversy / laragigs

Laravel job listing app
610 stars 421 forks source link

Undefined method 'listings'. [{ "resource": "/c:/xampp/htdocs/laraf/app/Http/Controllers/ListingController.php", "owner": "_generated_diagnostic_collection_name_#1", "code": "1013", "severity": 8, "message": "Undefined method 'listings'.", "source": "intelephense", "startLineNumber": 98, "startColumn": 11, "endLineNumber": 98, "endColumn": 19 }] #13

Open profprof-hub opened 2 years ago

profprof-hub commented 2 years ago

i am having issue with this line of code "return view('listings.manage', ['listings' => auth()->user()->listings()->get()]);". i try replacing it with the one on github but it still not working.

TechNech commented 2 years ago

I am facing the same issue/errors? Any fix for that? I tried Laravel Docs, stackoverflow etc.

TechNech commented 2 years ago

It seems to have fixed the problem when I replaced ' auth()->user()->listings()->get() ' to 'request()->user()->listings()->get()'.

profprof-hub commented 2 years ago

I have solved that issue by changing the access modifier of the listings() method from protected function listings (){
return $this->hasMany(Listing::class, 'user_id');
} to public function listings (){ return $this->hasMany (Listing::class, 'user_id'); } in the User Model.

profprof-hub commented 1 year ago

Yes, for now, the request () is the best solution to the problem.

On Sat, Aug 20, 2022, 8:22 PM TechNech @.***> wrote:

It seems to have fixed the problem when I replaced ' auth()->user()->listings()->get() ' to 'request()->user()->listings()->get()'.

— Reply to this email directly, view it on GitHub https://github.com/bradtraversy/laragigs/issues/13#issuecomment-1221391226, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2LL5INP2I4VN336HLNG5OLV2EV6DANCNFSM56WK3VLQ . You are receiving this because you modified the open/close state.Message ID: @.***>

profprof-hub commented 1 year ago

When you use the request() method in place of auth(), the error will disappear.

On Sun, Oct 9, 2022, 4:16 PM Iorawua. H Francis @.***> wrote:

Yes, for now, the request () is the best solution to the problem.

On Sat, Aug 20, 2022, 8:22 PM TechNech @.***> wrote:

It seems to have fixed the problem when I replaced ' auth()->user()->listings()->get() ' to 'request()->user()->listings()->get()'.

— Reply to this email directly, view it on GitHub https://github.com/bradtraversy/laragigs/issues/13#issuecomment-1221391226, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2LL5INP2I4VN336HLNG5OLV2EV6DANCNFSM56WK3VLQ . You are receiving this because you modified the open/close state.Message ID: @.***>

BesimCmega commented 1 year ago

I have solved that issue by changing the access modifier of the listings() method from protected function listings (){ return $this->hasMany(Listing::class, 'user_id'); } to public function listings (){ return $this->hasMany (Listing::class, 'user_id'); } in the User Model.

Where exactly? I have the modifier public and it's still not working.

paulrondario26 commented 1 year ago
"severity": 8,
"message": "Undefined method 'listings'.",
"source": "intelephense",
"startLineNumber": 99,
"startColumn": 67,
"endLineNumber": 99,
"endColumn": 75

Even if public function listings() is in User table the listings() method shows as undefined in listingcontroller.php

karizmaj commented 9 months ago

Undefined method 'listings'.intelephense(P1013): Seems like the plugin is just not recognizing the function, but it still works fine.

I just ignored it.

/** @disregard */
return view('listings.manage', [
    'listings' => auth()->user()->listings()->paginate() //intelephense marks this as an error but it works
]);
profprof-hub commented 9 months ago

Mine too is working fine, despite the error message

On Sun, Dec 17, 2023, 11:00 AM karizmaj @.***> wrote:

Undefined method 'listings'.intelephense(P1013): Seems like the plugin is just not recognizing the function, but it still works fine.

I just ignored it.

/* @disregard / return view('listings.manage', [ 'listings' => auth()->user()->listings()->paginate() //intellephense marks this as an error but it works ]);

— Reply to this email directly, view it on GitHub https://github.com/bradtraversy/laragigs/issues/13#issuecomment-1859096591, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2LL5IIGG4TRZNM2MIXXNATYJ27FHAVCNFSM56WK3VL2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBVHEYDSNRVHEYQ . You are receiving this because you modified the open/close state.Message ID: @.***>