У меня есть 3 таблицы с именами Order-factor - products , чтобы у меня есть код отслеживания. и в множителе i есть product_id и order_id. Как я могу получить заказ? : |Проблемы с laravel 5.1 Отношение
Например: order:where('trackingCode','HashCode')->ProductsInFactore()->get();
Заказ:
Schema::create('order', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('family');
$table->string('email');
$table->string('phone');
$table->string('state');
$table->string('city');
$table->string('address');
$table->string('PostalCode');
$table->boolean('status')->default(0);
$table->string('TrackingCode');
$table->timestamps();
});
Factore:
Schema::create('factor', function (Blueprint $table) {
$table->increments('id');
$table->integer('count');
$table->integer('order_id')->unsigned();
$table->integer('product_id')->unsigned();
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
$table->foreign('order_id')->references('id')->on('order')->onDelete('cascade');
$table->timestamps();
});
И продукты
заказа Модель
public function products()
{
return $this->hasManyThrough('App\products', 'App\factor','order_id','id','product_id');
}
Контроллер
$order = order::find(23)->products;
dd($order);