jeudi 25 janvier 2018

Laravel 5. Set the value of the Model custom attribute with separate service class

I've got some getter at the Order Model like this:

public function getProfitAttribute()
{
    return $this->service->calcProfit($this->order_amount);
}

and I need somehow to resolve this service class (that passed to the $this->service property) in the model.

How and where a better way to define that service class? At the Model constructor, inject directly to the Model method or somewhere in AppServiceProvider?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire