Hey,
If you feel this is too redundant or not the place to pose this question, feel free to blast this post away. @tabacitu is usually super-tuned in to these posts. I have searched through the tickets and Google, but I'm not sure I am asking the question the right way... or if there is even an answer out there...
I am running into situations where I have a Model that I would like to add multiple related (child) records too, using just one CRUD form. Some examples would include adding multiple files... but let's start small. I have found the following posts that have similar topics, but not clear answer on the best way to do this.
Is the best way to use the table Field Type? https://laravel-backpack.readme.io/docs/crud-fields#section-table But, I guess the drawback is not having validation on the child records?
A similar tutorial to this one would be cool: https://backpackforlaravel.com/articles/tutorials/nested-resources-in-backpack-crud
So, an example would be where I have a Journey model and would like to add multiple Chapters to the Journey directly on the same Journey CRUD form.
Let me know if this question makes sense... and any suggestions/advice you can share.
Thanks,
JFK
Sorry... I realized this isn't a bug and should be posted via another channel:
http://stackoverflow.com/questions/43723259/crud-adding-multiple-child-records-1-n-relationships-on-related-crud-form
Closing this "Issue".
@BinaryBlock Hey man I'm facing through the same question is there any advice that you can give me ? did you had luck on this?
@edgcarmu So... sorry. I didn't have any luck. The creator suggested the following on Stackoverflow:
My recommendation would be to edit the EntityCrudController::store() and EntityCrudController::update() methods, to check for the values of the "table" field and add/update/remove connected entries.
I ended up splitting out the relationships to other forms and the user would have to select which parent relationship they wanted to create a new child from. 馃槩
I believe there are other Laravel Admin systems that can handle (n-1 relationships) on the same CRUD form, but I have not used them. One example is Laravel Voyager
Hope that helps.
Update: We still don't have a built-in solution for this.
But a possible solution would be to have a 1-n field that allows you to add items (plus button that opens a modal with a form for the child record, hit save and it would be added to the db and selected in the select). It's mentioned elsewhere in our Github as "adding items on the fly".
This third-party package had a solution for Backpack v3, but for Backpack v4 we're working on a first-party solution. I'll try to update this thread as we work towards a complete solution for Backpack v4.
Sorry for the bad news.
I think many of us would like to have this :smile:
@aula2030 I have good news for you then 馃槃 We have it now 馃コ

When inside a create/update form, you can add related entities in a modal. We call the operation InlineCreate, check out the release notes here for a quick look https://backpackforlaravel.com/docs/4.1/release-notes#new-operation-inlinecreate
Then:
:smile: Oh, yes, I've seen that! After seeing your last comment I thought it was not complete (I'm using 4.1.16) :sweat_smile:
Sorry, I was thinking ahead and focusing on my problem.... I see now that the issue says "Adding child records", so you are right!! :+1:
But let me explain the situation (maybe I should open a new issue?):
In my test: I have Projects and Tasks (hasMany). When editing a project I have a relationship field with tasks. It retrieves the tasks list correctly. I can add a new task through the modal (the project is not assigned directly to the current one although I understand that it is something I must do), but the problem comes when, for any reason, I want to delete one task from the current project. This cannot be done. When you click on the cross, option disappears from list but obviously task FK to project in the DB is not updated (after saving)...

So I hoped, expected, wanted a way to "Delete child records" in a hasMany relationship. :sweat_smile: (similar to the behaviour of the table field). Maybe for the future.....?
Anyway, thanks for the great job!
@aula2030 that's odd. This field should definitely do both:
Yes, please open a differrent issue with your addField code and relationship definition in the models. It should be doing all that for you.
Hi @tabacitu! In this case it's not a pivot table. Projects and tasks have a 1:n relationship: 1 project - n tasks. So Tasks has a FK to Projects and when I delete a task from list in one project, it doesn't update the task record in the BD setting the FK to project to null (BD allows that).
@aula2030 I'v just submited a PR that I think addresses your issue. #3196
If you don't mind give it a go a test it out, give us your feedback in the PR thread, it will help us alot and speedup the merging process.
Wish you the best,
Pedro
@pxpm of course! My pleasure! This afternoon I'll check it :+1:
[EDITED]
I commented directly on the PR #3196
Most helpful comment
Update: We still don't have a built-in solution for this.
But a possible solution would be to have a 1-n field that allows you to add items (plus button that opens a modal with a form for the child record, hit save and it would be added to the db and selected in the select). It's mentioned elsewhere in our Github as "adding items on the fly".
This third-party package had a solution for Backpack v3, but for Backpack v4 we're working on a first-party solution. I'll try to update this thread as we work towards a complete solution for Backpack v4.
Sorry for the bad news.