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

DanielGG's avatar

BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::incomplete()'

I get this error when I try to call the function incomplete from my Task model using tinker.

Code:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;



class Task extends Model
{
    public static function incomplete()
    {
        return static::where('completed','=',0)->get();
    }
}

Command i'm using in php artisan Tinker:

App\Task::incomplete()

Can't seem to fix it

0 likes
11 replies
tykus's avatar

Why not a query scope?

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;



class Task extends Model
{
    public function scopeIncomplete($query)
    {
        return$query->where('completed', 0);
    }
}

Then, you can reuse any time you need incomplete task(s)

$incompleteTasks = Task::incomplete()->get();

$incompleteTasksAssignedToMe = Task::incomplete()->where('user_id', 123)->get();
1 like
DanielGG's avatar

I was watching episode 7 of 'Laravel 5.4 from scratch', so I didn't yet know about query scopes. Besides, this may fix my problem, but I'm still wondering why I get that error

Thanks for the help though!

tykus's avatar

Honestly, I don't know. If the code is as you have describe then the class should respond to incomplete() and not pass it up to the Query Builder. I would double check spellings, correct use of statickeyword. Beyond that, I would be at a loss without seeing more code.

asmi77's avatar

I had exactly the same error. I spend the evening to find out what was wrong with my code. I thought that it was because of my version of Laravel (5.6.). And finally, I just had to kill the tinker process and restart everything, and it did the trick.

If I change my code in the model, for example, I want to display the completed tasks (put 1 instead of 0), I change the code, then I need to kill the process, and restart it to get what it is expected. Otherwise, it doesn't work.

4 likes
crnkovic's avatar

I just tested the same code and it works fine for me (5.6.5).

Make sure to restart the Tinker when you make changes in your code.

1 like
forrestedw's avatar

Make sure to restart the Tinker when you make changes in your code.

I had the same problem and this solved it. Thank you.

ChristArt's avatar

I ran into the same problem while going through the video series. A Google search brought me here. Restarting tinker did the trick! Thank you!

Edelco's avatar

@ASMI77 - Restarting Tinker is the key after every change of the model ;-)

1 like

Please or to participate in this conversation.