Returned url empty?
Closed this issue · 6 comments
Hey, i think i have some error, if i return url its empty but in database is full json
"avatar":{"thumbnail":{"url":"\/uploads\/user\/2016\/12\/13\/59\/14\/50x50_crop\/zWpKdcRRHr7PUiKd.png","height":50,"width":50},"xsmall":{"url":"\/uploads\/user\/2016\/12\/13\/59\/14\/160x120\/zWpKdcRRHr7PUiKd.png","height":120,"width":137},"small":{"url":"\/uploads\/user\/2016\/12\/13\/59\/14\/240x180\/zWpKdcRRHr7PUiKd.png","height":180,"width":206},"profile":{"url":"\/uploads\/user\/2016\/12\/13\/59\/14\/300x300_crop\/zWpKdcRRHr7PUiKd.png","height":300,"width":300},"medium":{"url":"\/uploads\/user\/2016\/12\/13\/59\/14\/640x480\/zWpKdcRRHr7PUiKd.png","height":480,"width":549},"large":{"url":"\/uploads\/user\/2016\/12\/13\/59\/14\/800x600\/zWpKdcRRHr7PUiKd.png","height":482,"width":551},"original":{"url":"\/uploads\/user\/2016\/12\/13\/59\/14\/zWpKdcRRHr7PUiKd.png","height":null,"width":null}}
@Samuell1 Could you help me with the syntax you are using in the Model / Controller / View ?
If its a obj it should be $object->avatar->thumbnail->url
For the thumbnail type.
@mrigankmridul yes i using blade {{ $user->avatar->original->url }}
In model i have use SahusoftCom\EloquentImageMutator\EloquentImageMutatorTrait;
in class use EloquentImageMutatorTrait;
and protected $image_fields = ['avatar'];
with avatar fillable
Controller view
$user = Auth::user();
return view('auth.profile.index')->with('user', $user);
Laravel 5.3
If i try return only $user->avatar i get error htmlspecialchars() expects parameter 1 to be string, object given
then that json object exists
Any ideas why this happening?
@Samuell1
When passing information in this manner i mean using with
, $user should be an array with key/value pairs. Inside your view, you can then access each value using its corresponding key.
In the Controller view above you are passing as object hence its breaking. Please do
return view('auth.profile.index')->with('user', $user->toArray());
and send it to the view and access as
$user['avatar']['original']['url']
in the view.
OR
Try this, This should work too.
return view('auth.profile.index', ['user' => $user]);
instead of
return view('auth.profile.index')->with('user', $user);
I find i can do it like $user->toArray()['avatar']['profile']['url']
and its working too.
but thanks!
@Samuell1 Welcome 👍