Trying to show an image that is saved as a setting. setting('key.value').
It should have the storage/ prefix. Instead its path starts from settings/....
Create an image setting and try to show it on your front-end. Using HTTPS.
I have altered the code like so:
File TCG\Voyager\Voyager.php
public function setting($key, $default = null)
{
if ($this->setting_cache === null) {
foreach (self::model('Setting')->all() as $setting) {
$keys = explode('.', $setting->key);
// Lines added start here
if($setting->type == 'image') {
$setting->value = 'storage/' . $setting->value;
}
// Lines added end here
@$this->setting_cache[$keys[0]][$keys[1]] = $setting->value;
}
}
$parts = explode('.', $key);
if (count($parts) == 2) {
return @$this->setting_cache[$parts[0]][$parts[1]] ?: $default;
} else {
return @$this->setting_cache[$parts[0]] ?: $default;
}
}
so it will properly show the image.
I ain't sure if that's the proper solution though.
This solution will affect the admin logo and loader images from loading.
You will need to change these too:
<?php $admin_loader_img = Voyager::setting('admin.loader', ''); ?>
@if($admin_loader_img == 'storage/')
<img src="{{ voyager_asset('images/logo-icon.png') }}" alt="Voyager Loader">
@else
<img src="{{ Voyager::image($admin_loader_img) }}" alt="Voyager Loader">
@endif
<?php $admin_logo_img = Voyager::setting('admin.icon_image', ''); ?>
@if($admin_logo_img == 'storage/')
<img src="{{ voyager_asset('images/logo-icon-light.png', true) }}" alt="Logo Icon">
@else
<img src="{{ Voyager::image($admin_logo_img) }}" alt="Logo Icon">
@endif
You have to use:
{{ Voyager::image(setting('key.value')) }}
This will return an absolute path
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
You have to use:
{{ Voyager::image(setting('key.value')) }}This will return an absolute path