【发布时间】:2021-06-28 05:32:40
【问题描述】:
我想在产品Qty <= 0 时自动将产品状态更新为“不可用”,并使用触发器功能或使用模型将状态更新为“重新订购级别”Qty > 1 && Qty <= 5。我该如何解决这个问题?
这是我的产品表。
Schema::create('products', function (Blueprint $table) {
$table->bigIncrements('ProductID');
$table->string('Name');
$table->string('Brand');
$table->mediumText('image')->nullable();
$table->string('Description');
$table->string('Warranty');
$table->integer('Price');
$table->integer('Qty');
$table->string('Status')->nullable()->default("In Stock");
$table->unsignedBigInteger('AdminID');
$table->foreign('AdminID')->references('EmpID')->on('users');
$table->timestamps();
});
【问题讨论】:
-
您需要为
product创建一个观察者类,并在产品被删除、创建或更新后运行该函数
标签: laravel eloquent laravel-8