What is query() method for?

Posted 1 month ago by MartinZeltin

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();
    }
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.