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

后端 未结 5 699
野的像风
野的像风 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:06

    Unfortunately, @Chin's answer did not work for me as for Edit view the request class is just a basic Laravel\Nova\Http\Request class.

    My workaround to check if this is an index view is as follows:

    /**
     * Check if the current view is an index view.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest $request
     * @return bool
     */
    public function isIndex($request)
    {
        return $request->resourceId === null;
    }
    

提交回复
热议问题