Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
PhpStorm says find method not found

In laravel 8 I made a Model app/Models/Role.php

class Role extends Model
{
    use HasFactory;

    public function users(): BelongsToMany
    {
        return $this->belongsToMany(User::class);
    }
}

In routes/web.php I made route

Route::get('/role/{id}/user', function ($id) {
    $users = Role::find($id)->users()->get();
    foreach ($users as $user) {
        echo $user;
    }
});

PhpStorm shows error saying "Method 'find' not found in App\Models\Role". Please help me to fix this. Thanks

Show Screenshot

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Its only PhpStorm showing erorr.Ide is not able to recognize methods.If you call that route then get desired output.

To solve

Method 'find' not found in \App\Models\Role

just call query() method

 $users = Role::query()->find($id)->users()->get();

query() returns \Illuminate\Database\Eloquent\Builder

over 4 years ago · Santiago Trujillo Report

0

For Models in PhpStorm, this should be the definitive answer:

https://stackoverflow.com/a/48847159/1382828

Using @mixin \Eloquent in your models cures all headaches.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!