Image.php 997 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace Dcat\Admin\Grid\Displayers;
  3. use Illuminate\Contracts\Support\Arrayable;
  4. use Illuminate\Support\Facades\Storage;
  5. class Image extends AbstractDisplayer
  6. {
  7. public function display($server = '', $width = 200, $height = 200)
  8. {
  9. if ($this->value instanceof Arrayable) {
  10. $this->value = $this->value->toArray();
  11. }
  12. return collect((array) $this->value)->filter()->map(function ($path) use ($server, $width, $height) {
  13. if (url()->isValidUrl($path) || mb_strpos($path, 'data:image') === 0) {
  14. $src = $path;
  15. } elseif ($server) {
  16. $src = rtrim($server, '/').'/'.ltrim($path, '/');
  17. } else {
  18. $src = Storage::disk(config('admin.upload.disk'))->url($path);
  19. }
  20. return "<img data-action='preview-img' src='$src' style='max-width:{$width}px;max-height:{$height}px;cursor:pointer' class='img img-thumbnail' />";
  21. })->implode('&nbsp;');
  22. }
  23. }