Two BelongsTo fields depending on each other
#5748
-
|
Hey people. I have this entity, So, I have my full model now, and Nova resources are working well. Except that when I create a new So, you can never have both at the same time 😁 Here is the code I used: BelongsTo::make('Contact')
->dependsOn(
['project'],
function (BelongsTo $field, NovaRequest $request, FormData $formData) {
$projectId = $formData->get('project') ?? $formData->get('resource:projects');
// $contactId = $formData->get('contact') ?? $formData->get('resource:contacts'); // Maybe use this to re-set the value somehow?
$field->relatableQueryUsing(
function (NovaRequest $request, Builder $query) use ($projectId) {
$query->whereDoesntHave('contactProjects', function (Builder $query) use ($projectId) {
$query->where('project_id', $projectId);
});
});
}
),
BelongsTo::make('Project')
->dependsOn(
['contact'],
function (BelongsTo $field, NovaRequest $request, FormData $formData) {
$contactId = $formData->get('contact') ?? $formData->get('resource:contacts');
// $fieldValue = $formData->get('project') ?? $formData->get('resource:projects'); // Maybe use this to re-set the value somehow?
$field->relatableQueryUsing(
function (NovaRequest $request, Builder $query) use ($contactId) {
$query->whereDoesntHave('contactProjects', function (Builder $query) use ($contactId) {
$query->where('contact_id', $contactId);
});
});
}
),So, is there a way to set a value after refresh with Thanks ahead! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
This would create a circular dependency, no? |
Beta Was this translation helpful? Give feedback.
This would create a circular dependency, no?