Laravel Tips: OrderBy on Eloquent relationships [3]

You can specify ‚ÄčorderBy()‚Äč directly on your Eloquent relationships.

public function products() 
{
     return $this->hasMany(Product::class); 
} 
 public function productsByName() 
{
     return $this->hasMany(Product::class)->orderBy('name'); 
}