我正在制作一个库存管理系统。当产品缺货时,我会在表中输入一个条目并记下带有日期/时间的“oos_at”字段。
稍后,当它重新进货时,我找到了该条目并更新了“restocked_at”时间戳字段。
但是,当我执行第二个操作时,我的“oos_at”字段被查询('updated_at')字段的时间戳覆盖......我必须在另一个实体上跟踪这个“oos_at”字段,所以它不会被覆盖,然后在更新该表时使用该字段再次更新“oos_at”字段...
下面是我的代码......
class Pusher extends Model {
/**
*
*
* @param Carbon $oos_at
* @return bool
*/
public function setAsOutOfStock(Carbon $oos_at)
{
Log::info([
'FILE' => get_class($this),
'method' => 'setAsOutOfStock',
'pusher' => $this->id,
'param:oos_at' => $oos_at->toDateTimeString(),
]);
$this->pusherOutOfStocks()->create([
'location_id' => $this->location_id,
'product_id' => $this->product_id,
'oos_at' => $oos_at->toDateTimeString(),
]);
$this->oos = true;
$this->oos_at = $oos_at;
return $this->save();
}
/**
* Clear the PusherOutOfStocks attached to $this Pusher
* (This Pusher has been restocked!)
*
* @param Carbon $time
* …Run Code Online (Sandbox Code Playgroud)