簡體   English   中英

如何設置不同的字段集以在 Laravel nova 中創建和更新資源?

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

我想在創建和編輯資源時顯示具有不同設置的一組不同的字段。

如何使用 Laravel Nova 實現它?

您可以在 fields 函數中使用此條件來檢查這是更新還是創建請求,例如

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')
        ]
    }
}

更新:從 v3.1.0 開始,您可以使用以下方法:

  • 公共函數 fieldsForIndex(Request $request)
  • 公共函數 fieldsForDetail(Request $request)
  • 公共函數 fieldsForCreate(Request $request)
  • 公共函數 fieldsForUpdate(Request $request)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM