dimanche 29 novembre 2015

laravel 5.1 MarphToMany & MarphByMany with custom fields

I am having custom fields in table and want to MorpTohmany with other tables. how to do it with custom fields.

In below model (salepurchase) request_to is supplier model foreign key, where salepurchase_type and salepurchase_id these will contain other model relation, Like Warehouse, Shop etc

SalePurchase Model

+----+------------+-------------------+-----------------+-------------+
| id | request_to | salepurchase_type | salepurchase_id | total_items |
+----+------------+-------------------+-----------------+-------------+
|  1 |          1 | Warehouse         |               1 |          10 |
|  2 |          1 | Warehouse         |               1 |          10 |
|  3 |          1 | Warehouse         |               1 |          11 |
|  4 |          1 | Shop              |               7 |          15 |
|  5 |          1 | Shop              |               5 |          19 |
+----+------------+-------------------+-----------------+-------------+

Warehouse Model

+----+-------------+
| id | name        |
+----+-------------+
|  1 | warehosue 1 |
|  2 | warehosue 2 |

Shop Model

+----+-------------+
| id | name        |
+----+-------------+
|  5 | Shop 1      |
|  7 | Shop 2      |

Supplier Model

+----+--------------------------+
| id | qualified_person         |
+----+--------------------------+
|  1 | Marks                    |
|  2 | test                     |
+----+--------------------------+



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire