简体   繁体   中英

How can I set different sets of fields to create and update a resource in Laravel nova?

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:

  • public function fieldsForIndex(Request $request)
  • public function fieldsForDetail(Request $request)
  • public function fieldsForCreate(Request $request)
  • public function fieldsForUpdate(Request $request)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM