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

martinszeltins's avatar

What is query() method for?

I have noticed in a project a syntax like this but I could not find it on the Laravel docs anywhere. What is this syntax and why is it necessary?

class Email extends Model
{
    public function getEmails()
    {
        return self::query()
            ->where('id', 89)
            ->where('email', '[email protected]')
            ->get();
    }
}

Isn't it the same as this? What is the query() for?

class Email extends Model
{
    public function getEmails()
    {
        return self::where('id', 89)
            ->where('email', '[email protected]')
            ->get();
    }
}
0 likes
1 reply
ftiersch's avatar
ftiersch
Best Answer
Level 28

It's not necessary. It just gives you the current query builder object if you need to save it in a variable for example.

Please or to participate in this conversation.