0
注文コード - 製品 という名前のテーブルが3つあり、トラッキングコードがあります。ファクタ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);