-
Description:When I try create a new register (Asset), the following message is returned: "The Entity field is required.". Debugging I noticed that Laravel Nova sends the id for validation instead of the code field, which would be correct. Detailed steps to reproduce the issue on a fresh Nova installation:
I have a two models, entity and assets: In my assets Model I've entity method with BelongsTo relationship. public function entity(): BelongsTo
{
return $this->belongsTo(
Entity::class, // Eloquent model
Asset::ENTITY_CODE, // Foreing key
Entity::CODE, // Owner key
);
}In Entity Resource (Laravel Nova): public function fields(NovaRequest $request): array
{
return [
ID::make()->sortable(),
Text::make('Code')->hideWhenUpdating()->sortable(),
Text::make('Name')->sortable(),
Text::make('Description')->sortable(),
BelongsTo::make('Entity Code', null, Entity::class)
->dontReorderAssociatables()
->withoutTrashed()
->sortable()
->hideWhenUpdating()
->creationRules('exists:entities,code'),
];
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi there, Unfortunately, this is something that we are not able to support at the moment for various limitations and since it may be solved with an upcoming feature I don't think it is worth it to complicate In the meantime I believe you can use the following: BelongsTo::make('Entity Code', null, Entity::class)
->exceptOnForms()
->sortable(),
Select::make('Entity Code')
->options(function () {
return \App\Models\Entity::query()->pluck('name', 'code');
})->onlyOnForms()
->hideWhenUpdating()
->creationRules('exists:entities,code'), |
Beta Was this translation helpful? Give feedback.

Hi there,
Unfortunately, this is something that we are not able to support at the moment for various limitations and since it may be solved with an upcoming feature I don't think it is worth it to complicate
BelongsTofield at the moment.In the meantime I believe you can use the following: