L
L
Li2016-05-26 19:54:36
Laravel
Li, 2016-05-26 19:54:36

How to add multiple records to proxy table in laravel 5.2?

Hello. I am using Laravel 5.2. Faced the problem of multiple adding to the intermediary table.
There are 3 MySQL tables with the following structure:
objects ( object list )
: id
objects_categories ( object category list )
: id
objects_to_categories ( pivot table for the above tables )
: object_id, category_id
On the add objects page, you can activate multiple categories. The object itself must go into the objects table, and the categories of the object into the objects_to_categories table. I manage to solve it like this:
- add an object
- get the object id
- get an array of categories to add
- add all categories in a loop
Not very nice. So. How to solve this problem with the standard functionality of Laravel 5.2. I would be very grateful for help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2016-05-26
@cubaPro

https://laravel.com/docs/5.2/eloquent-relationship...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question