Reputation: 133
I have two table one is pivot table and other is normal table that is
user_pharmacies
user_pharmacies_id | user_id | pharmacy_id
user_price
price_id | product_id | user_pharmacies_id | price
you can see primary key of pivot table is foreign key in user_price table. My question is how to define the relation between these two table i don't want to make model of pivot table
Upvotes: 0
Views: 365
Reputation: 203
Which one is your pivot table? I do not think any of above is pivot table. For the above tables you have to use two models, but if you have any real pivot table then you do not need to create model for that pivot table in laravel. You can use eloquent relationship to fetch the data from pivot table.
For example, you have following three tables : users
, roles
and user_roles
then you only need to create models for users
and roles
table. You can use eloquent relationship to fetch data from pivot table.
Upvotes: 0
Reputation: 941
Your table structure is entirely wrong. Please read the laravel documentation first on how to properly setup relationships by using a pivot table.
Upvotes: 1