thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.78k stars 2.67k forks source link

Merge two models in one view #433

Open Jaquedeveloper opened 7 years ago

Jaquedeveloper commented 7 years ago

Description:

Let's say, for instance, I have a sales table and a products table. Each sales table contains N products and N services. I'd like to add products to my sales view, so when I create the sale I can add products to it. For now, it can be done by selecting multiple elements from products, but saving it as a string. I can create a sales_products, and a sales_services dropdown input and create the relationships, saving the ids as a string. I'd like to have a table in which I can relate sales_items to the sale and also to tell which type the item is and how many of each I have on the sale, so I can search by the sale_id and find the items related to it.

I can create a table which contains sale_id, item_id and item_type_id, but I would need to create a sale and open another view in order to relate it to the items, and also to create and save one item each time, selecting the sale, the item and the item_type.

I'd like to be able to select multiple items and relate them to the sale and saving them correctly on my database, not as a string, but in the correct way to relate sales_item to the sale in my database.

How can I make it? Is there any way to make it work as expected?

Here's a database model:

screen shot 2016-12-22 at 19 59 18

Here's an example of the result I'd like to obtain (in this case with services only):

screen shot 2016-12-22 at 20 07 37
fletch3555 commented 7 years ago

Looks like what you're trying to get is a HasManyThrough relation. I don't believe Voyager currently has this capability OOTB (@marktopper / @handiwijoyo, please correct me if I'm wrong), though we're open to Pull Requests.

marktopper commented 7 years ago

You're right @fletch3555, this is currently not supported.

adamcmoore commented 6 years ago

@Jaquedeveloper did you find a solution to this? I'm looking for the same feature, which I'd see as BREAD within BREAD.

rahimlis commented 6 years ago

same need

moisesh18 commented 5 years ago

Same need. I tried with input arrays, image but still not working because the function insertUpdateData uses !$request->hasFile($row->field) which is not prepared to manage input arrays...

image