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?

Source: laravel

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.