jeudi 21 mai 2015

Laravel inject sentry user into model

I keen to make my code decouple and ready for testing.

I have an Eloquent model getBudgetConvertedAttribute is depend on sentry user attribute.

public function getBudgetConvertedAttribute()
{
    return Sentry::getUser()->currency * $this->budget;
}

This throw error while testing because Sentry::getUser is return null.

My question is, How shall I code to inject user into model from controller or service provider binding or testing?

Aucun commentaire:

Enregistrer un commentaire