Как указано в комментарии, вы можете достичь этого с помощью многих полиморфных отношений
categories
id - integer
name - string
markets
id - integer
name - string
products
id - integer
name - string
productables
product_id - integer
productable_id - integer
productable_type - string
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
/**
* Get all of the products for the category.
*/
public function products()
{
return $this->morphToMany('App\Product', 'productable');
}
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Market extends Model
{
/**
* Get all of the products for the market.
*/
public function products()
{
return $this->morphToMany('App\Product', 'productable');
}
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
/**
* Get all of the categories that are assigned this product.
*/
public function categories()
{
return $this->morphedByMany('App\Category', 'productable');
}
/**
* Get all of the markets that are assigned this product.
*/
public function markets()
{
return $this->morphedByMany('App\Market', 'productable');
}
}
Чем вы можете получить товары, принадлежащие обоим(определенная категория и определенный рынок) с
$products = \App\Product::where(['productable_id' => $category->id, 'productable_type' => get_class($category)])->orWhere(['productable_id' => $market->id, 'productable_type' => get_class($market)])->get();
, исходя из вашего вопроса, что категория и рынок уже известны.
@ Решение YasinPatel тоже должно работать, но таким образом ваша архитектура БДявляется более гибким.Теперь тебе решать.Изучите решения полиморфных отношений, вам может быть интересно.