创建新数据时无法保存计算数据

时间:2018-10-22 04:01:08

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

型号

public static function findOrCreate($plan_id, $data)
{
    $fromDate = Carbon::now()->subDay()->startOfWeek();
    $nowDate = Carbon::now()->today();

    $spent_time = static::where('plan_id', $plan_id)->first();
    if (is_null($spent_time)) {
        return static::create($data);
    }else{

        $new_spent_time = SpentTime::first();
        $task_category = $new_spent_time->task_category;

        $new_spent_time->task_category = (['{task_category}' => $task_category, 
                                        '{daily_spent_time}' => $new_spent_time->daily_spent_time,
                                        '{daily_percentage}' => $new_spent_time->daily_percentage,
                                        '{spent_time}' => $new_spent_time->spent_time,
                                        '{percentage}' => $new_spent_time->percentage, $new_spent_time->task_category]);

        $new_spent_time->spent_time = $new_spent_time::where('task_category',$task_category)
                                    ->sum('daily_spent_time', $new_spent_time->daily_spent_time , $fromDate);
        $new_spent_time['spent_time'] = (int)$new_spent_time->spent_time + $spent_time->daily_spent_time;

        $new_spent_time->percentage = $new_spent_time::where('task_category',$task_category)
                                    ->sum('daily_percentage', $new_spent_time->daily_percentage, $fromDate);
        $new_spent_time['percentage'] = (int)$new_spent_time->percentage  + $spent_time->daily_percentage;
        $new_spent_time->save();
        return $spent_time->update($data);
    }
}
  

在创建具有相同类别的新数据库时,保存无法计算数据

enter image description here

  

这样的错误,并且在创建新数据时无法保存计算数据

enter image description here

0 个答案:

没有答案
相关问题