Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

abkrim's avatar
Level 13

External images. Location stored in json column

I'm looking for solution a resource with important data in json format (photos.urls)

{
    "raw": "https://images.unsplash.com/photo-1531214141683-bdcc6c193522?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjQ5NzYwfQ",
    "full": "https://images.unsplash.com/photo-1531214141683-bdcc6c193522?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjQ5NzYwfQ",
    "small": "https://images.unsplash.com/photo-1531214141683-bdcc6c193522?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjQ5NzYwfQ",
    "thumb": "https://images.unsplash.com/photo-1531214141683-bdcc6c193522?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjQ5NzYwfQ",
    "regular": "https://images.unsplash.com/photo-1531214141683-bdcc6c193522?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjQ5NzYwfQ"
}

I look 64robots/nova-fields, and work fine for extract json columns in resoruce details.

But I need, extract for example "thumb" column json, for use in for example, Laravel Nova External Image Field to be able to see in the resource list, the thumbnail

I'm going around the subject a bit, but I do not see an appropriate form, and I'm getting stuck. Any ideas?

Image Resource Photo

0 likes
3 replies
thaMink's avatar

Not sure what you're asking. Are you trying to extract the thumb from the JSON?

$data = json_decode($JSON);
$thumb = $json->thumb;

Or...not sure what you're asking for.

abkrim's avatar
Level 13
  1. Table with urls column woth format json.
  2. Nova
  3. Extract URL from urls (thumb)
  4. Aply this how image image in list of resource photo, such image

My code with nova:

use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use R64\NovaFields\JSON;
use Chaseconey\ExternalImage\ExternalImage;

public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('Unsplash','unsplash_id'),
            Text::make('Title', 'description'),
            ExternalImage::make('Image')
                ->prefix(function () {
                    $data = json_decode($this->urls);
                    return $data->thumb;
                })
        ];
    }

But fails

Argument 1 passed to Chaseconey\ExternalImage\ExternalImage::prefix() must be of the type string, object given, called in /Users/abkrim/Sites/multimedia/app/Nova/Photo.php on line 55 {"userId":1,"email":"[email protected]","exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Argument 1 passed to Chaseconey\ExternalImage\ExternalImage::prefix() must be of the type string, object given, called in /Users/abkrim/Sites/multimedia/app/Nova/Photo.php on line 55 at /Users/abkrim/Sites/multimedia/vendor/chaseconey/nova-external-image/src/ExternalImage.php:24)

If use this

    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('Unsplash','unsplash_id'),
            Text::make('Title', 'description'),
//            ExternalImage::make('Image')
//                ->prefix(function () {
//                    $data = json_decode($this->urls);
//                    return $data->thumb;
//                })
            Text::make('url', function () {
                    $data = json_decode($this->urls);
                    return $data->thumb;
                })
        ];
    }

I see text of link, but I like code for see an image.

Best regards.

abkrim's avatar
Level 13

Well, after some ideas I get solution.

...
use Chaseconey\ExternalImage\ExternalImage;
...

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),
        Text::make('Unsplash','unsplash_id'),
        Text::make('Title', 'description'),

        ExternalImage::make('Image', 'url_regular')

    ];
}

In my model Photo

...
public function getUrlRegularAttribute()
{
    $data = json_decode($this->urls);
    return "{$data->regular}";
}

public function getUrlThumbAttribute()
{
    $data = json_decode($this->urls);
    //$uri = str_replace('https://images.unsplash.com/', '', $data->thumb);
    //return "{$uri}";
    return "{$data->thumb}";
}

Photos Example

1 like

Please or to participate in this conversation.