area17 / twill

Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive, powerful and flexible. Chat with us on Discord at https://discord.gg/cnWk7EFv8R.
https://twillcms.com
Apache License 2.0
3.71k stars 567 forks source link

added support for medias in json repeaters #2554

Closed zeezo887 closed 3 months ago

zeezo887 commented 5 months ago

Description

This PR allows support for adding media in JSON repeaters. Media items for json repeaters are now saved in the mediables table role column in {$repeatedName}|{$repeaterIndex}|{$role} format. Also added a helper method to easily get the role for a JSON repeater.

if (! function_exists('getJsonRepeaterMediaRole')) {
    function getJsonRepeaterMediaRole($role, $repeaterName, $index): string
    {
        return "$repeaterName|$index|$role";
    }
}

If you have a JSON repeater with medias named features, you can display the image like so:

@foreach($item->features as $index => $feature)
    <img src="{{ $item->image(getJsonRepeaterMediaRole($role, 'features', $index), 'mobile') }}">
@endforeach