I have two tables in my database, one for "sales" informations and the other for "sale content" (items). What is the best method to present this using the laravel models? For example, is it better to create a model for each table or can we only use one?
Asked
Active
Viewed 19 times
1 Answers
0
A Model for each table - you cannot use one Model for multiple tables.
Laravel tries to infer the table name from the Model name based on lowercase pluralisation - so if your Model is called Sale it will presume that the table is called "sales". If your table is something else, you defined the table in the Model using :
protected $table = "online_sales";
Then you will need to define the relationships between the two models - the documentation is here : https://laravel.com/docs/8.x/eloquent-relationships

Giles Bennett
- 1,509
- 1
- 12
- 15
-
It's Giles (personal name first, family name second for me) - you're more than welcome. Please mark the answer as the accepted answer if you're happy with it. – Giles Bennett Dec 10 '21 at 14:05
-
I will do it now – Omar Dec 11 '21 at 02:35