I want to show a different set of fields with different settings when creating and editing a resource.
how to implement it with Laravel Nova ?
You can use this condition inside the fields function to check if this is an update or create request, For example
public function fields(Request $request)
{
if($request->resourceId === null)
{
//this is a create request
return
[
ID::make('ID', 'tenant_id')->sortable(),
Text::make('Userame', 'username'),
Image::make('Profile', 'user_file')
]
}
else
{
return
[
ID::make('ID', 'tenant_id')->sortable(),
Image::make('Profile', 'user_file')
]
}
}
Update: Since v3.1.0 you can use the following methods:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.