Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False detection when using count? #101

Open
philharmonie opened this issue Apr 6, 2023 · 2 comments
Open

False detection when using count? #101

philharmonie opened this issue Apr 6, 2023 · 2 comments
Labels
good first issue Good for newcomers

Comments

@philharmonie
Copy link

I am using the following code to count a user's open tasks:

$tasks_count = Auth::user()->tasks()->whereCompleted(false)->count();

The plugin tells me:

Model: App\Models\User => Relation: App|Models\Task - You should add "with ('App\Models\Task')" to eager-load this relation.
Model: App\Models\Task => Relation: user - You should add
"with ('user')" to eager-load this relation.

When I do that, the issue still occurs:

$tasks_count = Auth::user()->tasks()->with('user')->whereCompleted(false)->count();

Using

$tasks_count = Auth::user()->with('tasks')->tasks()->whereCompleted(false)->count();

gives me Call to undefined method Illuminate\Database\Eloquent\Builder::tasks() but user has a tasks relationship:

class User extends Authenticatable
{
    // ...

    public function tasks()
    {
        return $this->hasMany('App\Models\Task');
    }
@philharmonie
Copy link
Author

$tasks_count = Auth::user()->load('tasks')->tasks()->whereCompleted(false)->count();

@mechelon
Copy link
Member

mechelon commented Oct 4, 2024

Do you get the same alert with $tasks_count = Auth::user()->tasks()->whereCompleted(false)->get();?

@mechelon mechelon added the good first issue Good for newcomers label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants