0

I would like to push in my eloquent model an extra attribute on calculation and I would like to use it in my blade as $user->avatarImg my model method look like

 public function avatarImg()
 {

     if($this->hasMedia('avatar')) {
         $image = $this->getMedia('avatar');
         $img = \Intervention\Image\ImageManagerStatic::make($image[0]->getPath())->encode('data-url');
     }
     elseif ($this->blob->file) {
         $img = 'data:image/jpeg;base64,'. base64_encode($this->blob->file);
     } else {
         $img = '';
     }


     $this->user->put('avatarImg', $img);

     dd($this->user);

     return $img;

 }

but what I try does not working I get:

Call to a member function put() on null 

how would I do this properly?

deroccha
  • 1,181
  • 4
  • 22
  • 41
  • Take a look at [this question](https://stackoverflow.com/questions/17232714/add-a-custom-attribute-to-a-laravel-eloquent-model-on-load), may help you – Gabriel Caruso Sep 18 '17 at 15:45

1 Answers1

1

Looks like property user does not exists in your model. If this is User model try just

$this->put('avatarImg', $img);