管理面板中订单与订单状态表之间的关系

问题描述 投票:0回答:1

我正在创建ordersorder_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();
        });
    }
}
php laravel laravel-5.8 laravel-6
1个回答
0
投票

[从外观上看,一个订单可以具有多个OrderStatuses。为了在Eloquent中简化此操作(此处未介绍),您的order_status表需要引用orders表的另一列。

将此添加到order_status迁移中:

$table->bigInteger('order_id')->unsigned()->index();
$table->foreign('order_id')->references('id')->on('orders');
© www.soinside.com 2019 - 2024. All rights reserved.