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.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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();
}
}
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.