I'm stuck with putting a html output in Laravel 7 & nova 3.8
according to: https://nova.laravel.com/docs/3.0/search/global-search.html#title-subtitle-attributes
i try to make a function that put a html image in front of some resource on index pages:
public function title()
{
    return "<img width='20px' height='10px' src='./flags/".$this->country.".png' >";
}
I read that laravel 7 use {!! !!} ( https://laravel.com/docs/7.x/blade#displaying-data ) But if i use it in resource file in app/nova/some-resource.php php gives error.
How to easy put a image based on country field in resource title ?
I tried to create a Text field in my resource as it can have ->asHtml() and i have a nice flag image on index and detail view
public function fields(Request $request)
{
    return [ 
(...)
Text::make('Country Flag',
            function () {
            return "<img width='20px' height='10px' src='http://fishmarket.nowakadmin.com/flags/".$this->country.".png' >";
        })->asHtml(), 
(...)
]};
and in title i changed to:
public function title()
{
    return $this->country_flag.' '.$this->name;
}
Result is that title looks like
''' '.$this->name // it looks like $this->country_flag = '';
                The only wat to achieve goal of use html in field as i found:
Instead of just belongsTo i used Stack to use html in Text and data from other needed fields:
Stack::make('Details', [
            Text::make('Country',
            function () {   
                $flaga = DB::table('companies')->where('id', $this->company_id)->first();
                return "<img width='20px' height='10px' src='/flags/".$flaga->country.".png'> ".$flaga->country;
            })->asHtml()
            ->sortable(),
            
            BelongsTo::make('Company')
                ->default(function ($request) {
                    return $request->user()->company_id;
                })
                ->sortable(),
        ]),
And i have some html with flag image and company id in single field on resource without even touching resource $title
try this:
// for index
public static function label()
{
    // input your logic to show label
    return 'Your Label Index';
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With