You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i found in stapler docs that it should return attachment sizes with full path when returning data as json, but it does not seem to work with laravel-stapler
The stapler trait doesn't currently 'automagically' add it when you cast to JSON, so you'll need to handle this yourself. One option is to add it to the toArray() method of your model like this:
/**
* Convert the model instance to an array.
*
* @return array
*/
public function toArray()
{
return array_merge(parent::toArray(), ['avatar' => $this->attachments['avatar']]);
}
It'll then be encoded to JSON along with the rest of the model attributes/relationships.
Activity
tabennett commentedon Jun 20, 2016
The stapler trait doesn't currently 'automagically' add it when you cast to JSON, so you'll need to handle this yourself. One option is to add it to the
toArray()method of your model like this:It'll then be encoded to JSON along with the rest of the model attributes/relationships.
draaslan commentedon Jul 26, 2017
Also there is an another method like below.
You can add this to your model.
public function getFullPathAttribute() { return $this->avatar->url(); }And then add 'full_path' to the $appends to bind it to every json data.
protected $appends = ['full_path'];