Laravel: Is Having 2 Pivot Tables Between 2 Models Possible?
In my project I have 2 models:
Actions: 'deliver', 'order', 'used', 'spoiled'
Pivot Tables: : item_order, item_transaction
Here's what I want to achieve
- Have one Transaction table to record actions done to items
- If action is 'order' then it will save the request form to item_order pivot table,
- Otherwise, if action is 'deliver', 'used' or 'spoiled' it will record to 'item_transaction' pivot table.
I know I could make another table called 'order' but it will defeat the purpose of having only one 'transaction' table for easier monitoring of actions done to items.
Is it possible to have two different pivot tables between two models? How will I create the relationship?
Here's the link to an image of my Database Structure
As proposed in comment, your
item_transaction is tied to
transactions row. Since it can be only one of action (
transactions 1:m actions) solution could be to set
order_qty field as nullable field into
item_transaction table and completely removing
item_order table. Having it
null in there it can also be flag wether action is order wether something else.
- → "failed to open stream" error when executing "migrate:make"
- → I can't do a foreign key, constraint error
- → Setting a default value on settings form return null in Octobercms
- → Eloquent Multitable query
- → "Laravel 5.1" add user and project with userId
- → Image does not go in database with file name only tmp name saved?
- → Database backup with custom code in laravel 5 and get the data upto 10 rows from per table in database
- → Trait 'IlluminateFoundationBusDispatchesJobs' not found
- → Setting the maxlength of text in an element that is displayed
- → laravel check between 2 integer from database
- → how to retrieve image from database in laravel 5.1?
- → relationship for database Column type object
- → Carousel in Laravel 4 does not show as expected