如果模型对应的表是个没有主键或者复合主键的表,就没法用 increment 或 decrement 了
protected function incrementOrDecrement($column, $amount, $extra, $method)
{
$query = $this->newQuery();
if (! $this->exists) {
return $query->{$method}($column, $amount, $extra);
}
$this->incrementOrDecrementAttributeValue($column, $amount, $extra, $method);
return $query->where(
$this->getKeyName(), $this->getKey()
)->{$method}($column, $amount, $extra);
}
Model类的increment、decrement方法里用了$this->getKeyName(),就是获取主键。
可以自己加上 where条件
主键id,程序执行increment这一步,就卡死!写原生立马跑完