Cannot save calculation data by category when create new data in laravel

前端 未结 2 757
小鲜肉
小鲜肉 2021-01-16 19:52

Model SpentTime

I am unable save calculation data by category when create new data in laravel

public static function findOrCreate($plan_id, $data)
         


        
2条回答
  •  天涯浪人
    2021-01-16 20:21

    Model

    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);
        }
    }
    

提交回复
热议问题