我正在orders
和order_status
表之间创建外键关系。当我从客户那里收到新订单并发货时,我将订单状态设置为已收到该客户的发货。我设置了已发货和已接收状态,然后该订单将开始显示在“订单历史记录”页面上。我这样做正确吗?
class CreateOrdersTable extends Migration
{
public function up()
{
Schema::create('orders', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('customer_name');
$table->string('customer_email');
$table->string('customer_contact');
$table->bigInteger('order_status_id')->unsigned();
$table->string('product_names');
$table->string('products_quantity');
$table->text('customer_address');
$table->timestamps();
});
}
这是order_status表:
class CreateOrderStatusTable extends Migration
{
public function up()
{
Schema::create('order_status', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('status')->nullable();
$table->timestamps();
});
}
}
答案 0 :(得分:0)
从外观上看,一个Order可以具有多个OrderStatuses。为了在Eloquent中简化此操作(此处未介绍),您的order_status
表需要另外一列引用orders
表。
将此添加到order_status
迁移中:
$table->bigInteger('order_id')->unsigned()->index();
$table->foreign('order_id')->references('id')->on('orders');