Comments (14)
This has been fixed as of 1.0.4.
from laravel-nova-nested-form.
@yassipad This doesn't look like it worked. It still creates the main resource if the child resource fails validation on 1.0.4 for me
from laravel-nova-nested-form.
Can you send me your fields array with validation rules? It works fine even with deeply nested fields by me...
from laravel-nova-nested-form.
Parent
return [
Text::make('Name')
->rules('required'),
Text::make('Email')
->sortable()
->rules('required', 'email', 'max:254')
->creationRules('unique:members,email')
->updateRules('unique:members,email,{{resourceId}}'),
HasMany::make('Memberships'),
NestedForm::make('Memberships')
->max(1),
];
Nested
return [
BelongsTo::make('Member')
->hideWhenCreating(),
BelongsTo::make('Plan')
->rules('required'),
Date::make('Start Date')
->rules('required'),
Date::make('End Date')
->hideWhenCreating(),
];
from laravel-nova-nested-form.
Well, to be honest I have no idea why you’re getting that behaviour… I just tested it with your exact resource fields and it works as expected. Besides, the parent could not be created, since the nested logic happens after calling the « $resource::fill() » method of the parent resource and validation exceptions are thrown before the « $model->save(); » is called… Can you send a gif or something so I can see your creation flow?
from laravel-nova-nested-form.
Heres a video. Thanks for looking into this!
https://www.dropbox.com/s/2hy1zzdr5i4i8ef/Untitled1.mov?dl=0
from laravel-nova-nested-form.
Can you make sure this is the latest version of the plugin?
composer remove yassi/nova-nested-form
composer clearcache
composer require yassi/nova-nested-form 1.0.4
from laravel-nova-nested-form.
I tried the above and no luck. I also tried clearing laravel cache, restarting local web server and performing in incognito windows. I'll play around some more and see what I can figure out.
My composer.lock has the version e5a64e6587f4d8de428d3d9eb5b4192952ad0af2
which is correct.
from laravel-nova-nested-form.
What about you nova version?
from laravel-nova-nested-form.
1.1.7
from laravel-nova-nested-form.
Well, then I don’t know... sorry!
from laravel-nova-nested-form.
I use https://github.com/hyn/multi-tenant so perhaps this is the issue. My field definition is really this as it's not looking in the default database. Either way, it appears that this is an issue isolated to my project. I will give this a try on a fresh install of Nova and see. But for now, I'm closing this.
Text::make('Email')
->sortable()
->rules('required', 'email', 'max:254')
->creationRules('unique:tenant.members,email')
->updateRules('unique:tenant.members,email,{{resourceId}}'),
from laravel-nova-nested-form.
The problem exists in creation form when a unique
rule is applied:
protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
{
if ($model->exists) {
$newRequest = NovaRequest::createFrom($request);
$children = collect($newRequest->get($requestAttribute));
$newRequest->route()->setParameter('resource', $this->resourceName);
$this->deleteChildren($newRequest, $model, $children);
$this->createOrUpdateChildren($newRequest, $model, $children, $requestAttribute, $this->getRelatedKeys($newRequest));
} else {
$model::saved(function ($model) use ($request, $requestAttribute, $attribute) {
$this->fillAttributeFromRequest($request, $requestAttribute, $model, $attribute);
});
}
}
If the model does not exists else statement gets executed.
It add a listener on saved
event of the model.
If the validationException occurred creating children, the main model gets created
from laravel-nova-nested-form.
Ok, I discovered a lot of things:
Nova uses transactions in StoreController, so this is what happens if a child is not valid:
- nova create a transaction
- parent is inserted
- child throw validation
- nova rollback transaction
You can easily test this scenario watching your parent resource id. Every time a child is not valid, a new "autoincremented" id get burned. I tried about 20 times and my autoincrement counter increased without having saved record.
I don't like so much this implementation but it worked except when you have unique validation rules.
@yassipad I think you/we should change fillAttributeFromRequest
in order to pre-validate children before parent model creation.
from laravel-nova-nested-form.
Related Issues (20)
- Global search is broken, when using NestedForm HOT 4
- Changing text when there is no data HOT 2
- Multiple subresources are created when Observer saves main resource again HOT 2
- How to pass a parameter to child nested form? HOT 7
- Help text is not displayed HOT 6
- The nested relationship model is often not yet available in the parent object observer created() method
- What's the best way to translate things in LNNF HOT 2
- Second nested form display index incorrect
- Nested form validation not working. HOT 1
- Nested Form not working after update laravel 7 and nova 3
- defining the inverse - Whats's wrong? HOT 2
- Touch related items
- Is there anyway to override file field
- Support for Laravel Nova Advanced media library HOT 2
- Slow result rendring while using with BelongsTo field
- Support for Laravel Nova 4 HOT 15
- How to hide relationship column
- Question: is it possible to show related resources not only when editing, but when viewing main resource too?
- Trying to get property 'resourceClass' of non-object
- The Add new Record button is not adding the correct index
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-nova-nested-form.