Laravel Nova 리소스 제목에서 html을 사용하는 방법

Aug 21 2020

Laravel 7 및 nova 3.8에 html 출력을 넣어야합니다.

에 따르면 : https://nova.laravel.com/docs/3.0/search/global-search.html#title-subtitle-attributes

인덱스 페이지의 일부 리소스 앞에 html 이미지를 배치하는 함수를 만들려고합니다.

public function title()
{
    return "<img width='20px' height='10px' src='./flags/".$this->country.".png' >";
}

나는 laravel 7 사용 {!! !!} (https://laravel.com/docs/7.x/blade#displaying-data )하지만 app / nova / some-resource.php의 리소스 파일에서 사용하면 php에서 오류가 발생합니다.

리소스 제목에 국가 필드를 기반으로 이미지를 쉽게 넣는 방법은 무엇입니까?

-업데이트 23.08.2020

내 리소스에 텍스트 필드를 만들려고했습니다.-> asHtml ()을 가질 수 있고 인덱스 및 상세보기에 멋진 플래그 이미지가 있습니다.

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(), 
(...)
]};

그리고 제목에서 나는 다음과 같이 변경했습니다.

public function title()
{
    return $this->country_flag.' '.$this->name;
}

결과는 제목이

''' '.$this->name // it looks like $this->country_flag = '';

답변

Pace Aug 23 2020 at 03:58

이 시도:

// for index
public static function label()
{
    // input your logic to show label
    return 'Your Label Index';
}
NoAd Sep 04 2020 at 03:38

내가 찾은 것처럼 현장에서 html 사용 목표를 달성하는 유일한 방법은 다음과 같습니다.

내가 속한 대신 스택을 사용하여 텍스트 및 다른 필요한 필드의 데이터에서 html을 사용했습니다.

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(),
        ]),

그리고 리소스 $ title을 건드리지 않고도 리소스의 단일 필드에 플래그 이미지와 회사 ID가있는 HTML이 있습니다.