所以,我有一个客户可以订购食物的项目。产品存储在购物车中,然后插入数据库中。我想设计订单和产品表,但我也想存储每个产品的数量和小计价格。订单和产品有N:N关系。以下是我的表格迁移:
Schema::create('orders', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('product_id');
$table->enum('status',['open','closed']);
$table->timestamps();
});
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description')->nullable();
$table->float('price',8,2);
$table->string('image_path');
$table->timestamps();
});
数据透视表:
Schema::create('order_product', function (Blueprint $table) {
$table->integer('order_id')->unsigned()->nullable();
$table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
$table->integer('product_id')->unsigned()->nullable();
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
$table->timestamps();
});
我看到解决方案的方式是:
你能指点我一个更好的解决方案吗?我是网络开发的新手。