按相同类别创建新数据时无法保存数据

时间:2018-10-23 09:19:59

标签: php laravel-5 sum laravel-query-builder laravel-5.7

型号

  

错误:   “数组到字符串的转换(SQL:更新spent_times设置updated_at = 2018-10-23 09:16:43,spent_time = 16,percentage = 70,{{ 1}} =测试task_category = 1)◀“

id
  

为什么只有第一个ID?

1 个答案:

答案 0 :(得分:0)

更新答案

型号

public static function findOrCreate($plan_id, $data)
{
    $spent_time = static::where('plan_id', $plan_id)->first();
    $task_category = $spent_time->task_category;

    if (is_null($spent_time)) {
        return static::create($data);
    }else{
        $spent_time['spent_time'] = $spent_time->spent_time + $spent_time->daily_spent_time;

        $spent_time['percentage'] = $spent_time->percentage  + $spent_time->daily_percentage;
        return $spent_time->update($data);
    }
}