Level 88
You need to add the css to the img tag itself
Text::make('Image Preview 1', function() {
return sprintf(
'<img style="%s" src="%s">',
'height=20px;width=auto',
$this->image_url_1
);
})->asHtml();
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to apply a CSS style class to an image preview field in Laravel Nova, but I'm not sure if it's possible. I've tried this:
Text::make('Image Preview 1', function() {
return "<img src={$this->image_url_1}>";
})->asHtml()->withMeta(
[
'style' => 'height=20px;width=auto'
]
),
and I've tried this:
Text::make('Image Preview 1', function() {
return "<img src={$this->image_url_1}>";
})->asHtml()->withMeta(
['extraAttributes' => [
'style' => 'height=20px;width=auto']
]
),
Neither worked. I've scouted the documentation and google and just really struggling to find out if this is possible. Any clues?
You need to add the css to the img tag itself
Text::make('Image Preview 1', function() {
return sprintf(
'<img style="%s" src="%s">',
'height=20px;width=auto',
$this->image_url_1
);
})->asHtml();
Please or to participate in this conversation.