Laravel-admin: Model show multiple images preview

Created on 2 Nov 2018  ·  9Comments  ·  Source: z-song/laravel-admin

  • Laravel Version: 5.6
  • PHP Version: 7.1+
  • Laravel-admin: 1.6.5

Is it possible to preview multiple images in model show??

When I do $show->photos()->image() it throws an error "array to string conversion".

Thanks in advance.

wontfix

Most helpful comment

So I found a workaround, I am not sure if it is a good approach but it is working.
If anyone have a better idea I will be glad to hear it.
Bellow is a snapshot of my code

image

All 9 comments

if $show->photos() is a collection use first() method to display to the first image

example:
$show->photos()->first()->image_name

But I want to display all images...like in form where you have multipleImage

you have to loop the image collections

Well I tried $show->photos()->each()->image() and still got an error "parameter expects to be string, array given" I even tried your example and still got the same error...

So I found a workaround, I am not sure if it is a good approach but it is working.
If anyone have a better idea I will be glad to hear it.
Bellow is a snapshot of my code

image

i do that like you

这个方法也不错

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Well I tried $show->photos()->each()->image() and still got an error "parameter expects to be string, array given" I even tried your example and still got the same error...

This one worked for me, Just need to add a function __toString on Photo Model that returns the image path.

public function __toString() { return $this->path; }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amun1303 picture amun1303  ·  3Comments

vlongen picture vlongen  ·  3Comments

zhenyangze picture zhenyangze  ·  3Comments

benny-sun picture benny-sun  ·  3Comments

cdhraesaemer picture cdhraesaemer  ·  3Comments