Wednesday, March 15, 2017

scopeMethods not found in controller PHPstorm Laravel5

Im new to php and laravel so perhaps im doing something wrong. I'm following along to Jeffrey Way's Laracasts tutorials and he creates a "query scope" method.

When I then use that in my controller, it says it cant find it.

so in my Task model I have:

public static function scopeCompleted( Builder $query )
{
    return $query->where( 'completed', 1 );
}

in my controller I have:

$completed_tasks = Task::completed()->get();

but completed is highlighted by PhpStorm with the error:

"Method 'completed' not found in App\Task"

I know its looking for a method called scopeCompleted, but this is not how you call a query scope method in the controller.

Am I doing something wrong or is this just a flaw in phpstorm?

fyi: the code functions perfectly well.



via Brad

Advertisement