【问题标题】:Relation between order and order status table in admin panel管理面板中订单和订单状态表之间的关系
【发布时间】:2019-10-03 18:33:51
【问题描述】:

我正在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】:

从外观上看,一个订单可能有多个订单状态。为了在 Eloquent 中实现这一点(此处未介绍),您的 order_status 表需要另一个引用 orders 表的列。

将此添加到order_status 迁移:

$table->bigInteger('order_id')->unsigned()->index();
$table->foreign('order_id')->references('id')->on('orders');

【讨论】:

  • 好的先生,我已经添加了这些行,但请告诉我这是在订单中添加订单状态的正确方法,意味着制作单独的订单状态表并将其连接到订单表???? ??????????
  • 我使用 this 作为 Eloquent 的首选参考,但如果您提出这个问题,您可以从教程中受益。我推荐 Jeffrey Way 的优秀 Laracasts 系列,Laravel 5.7 From Scratch
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-04
  • 1970-01-01
  • 2017-01-22
  • 2017-07-22
  • 2013-04-30
  • 1970-01-01
  • 2012-04-26
相关资源
最近更新 更多