Skip to content

Instantly share code, notes, and snippets.

@chrispymm
Created June 10, 2020 06:51
Show Gist options
  • Save chrispymm/9a2542a91732c8b65cebf3ca5ad0d6b0 to your computer and use it in GitHub Desktop.
Save chrispymm/9a2542a91732c8b65cebf3ca5ad0d6b0 to your computer and use it in GitHub Desktop.
[Enable media upload on settings pages] #twill

In order to upload the image in the crops for the image need to be added to the settings array in the twill config file.

'settings' => [
        'crops' => [
            '[NAME]' => [
                '[CROP]' => [
                    [
                        'name' => 'foobar',
                        'ratio' => 1,
                    ],
                ],
            ],
        ],
    ],

To retrive the image you cannot use the standard app(SettingRepository::class)->byKey('key','section') method. This is because this method will automatically (and only) return values from the setting_translations DB table. Instead you must access the setting directly:

use A17\Twill\Models\Setting;

$setting = Setting::firstWhere('key', 'setting_name');
$img = $setting->imageObject('role_name');
@adam-jones-net
Copy link

I can't get images working in settings. So just to clarify, a crop definition is required in the main twill config file and also within the properties of the view where the media field is defined ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment