TIP 04 / 36

Conditional Relationships.

If you notice that you use same relationship often with additional "where" condition, you can create a separate relationship method.

Model:

code
public function comments()
{
    return $this->hasMany(Comment::class);
}

public function approvedComments()
{
    return $this->comments()->where('approved', 1);
}