Hello everyone, I would like to ask for help in order to refute relations in the models in Laravel. I have a table of the form:
------------|------------|------------|--------------| City | Category |Subcategory | Company | ------------|------------|------------|--------------| id | id | id | id | | city_id |category_id |subcategory_id| name | name | name | name | ------------|------------|------------|--------------| City.php
public function categories() { return $this->hasMany(Category::class); } Category.php
public function subcategories() { return $this->hasMany(Subcategory::class); } Subcategory.php
public function category() { return $this->hasMany(Company::class); } In general, the problem is that there are many cities and the categories may be the same for all cities, in my case, the categories are repeated for each city, yesterday I thought about it all day, tried all possible relations with Laravel and could not think out any logic. Example: If I add for example a new city and after that I want to attach categories to it and each time it turns out that I create a new and duplicate category for just 1 city ... I really hope for help ... How can I do this correctly !?
The logic is as follows: We have cities that have many companies and these companies are divided into categories and subcategories. How to zoon.ru done. Choose a city, categories appear at the bottom of the subcategory.