Laravel Nova - How to determine the view (index, detail, form) you are in for a resource's computed field?

后端 未结 5 697
野的像风
野的像风 2021-01-19 07:21

I would like to return a different result for a computed field when viewing the index view than when viewing the detail view of a resource.

Basically something like

5条回答
  •  借酒劲吻你
    2021-01-19 08:04

    You can create two separate fields for index & details page.

    // ----- For Index page
    Text::make('Preview', function () {
        return \small_preview($this->image);
    })
    ->onlyOnIndex()
    ->asHtml(),
    
    // ----- For Detail page
    Text::make('Preview', function () {
        return \large_preview($this->image);
    })
    ->onlyOnDetail()
    ->asHtml(),
    

提交回复
热议问题