Как сделать решения для преобразования массивов в строки?

Скриншот

Модель

"Преобразование массива в строку (SQL: обновление spent_times set updated_at = 2018-10-18 07:20:22, spent_time = 12, percentage = 60,00, task_category = тестирование, где id = 7) ◀"

<?php

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

    $spent_time = static::where('plan_id', $plan_id)->first();

    if (is_null($spent_time)) {
        return static::create($data);
    } else {

        $new_spent_time = SpentTime::find($plan_id);
        $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->spent_time = $new_spent_time::where('task_category', 'LIKE', (array)"%$task_category%")
            ->sum('daily_spent_time', 'LIKE', (array)"%$new_spent_time->daily_spent_time%", $fromDate);
        $request['spent_time'] = (int)$new_spent_time->spent_time + $spent_time->daily_spent_time;

        $new_spent_time->percentage = $new_spent_time::where('task_category', 'LIKE', (array)"%$spent_time->task_category%")
            ->sum('daily_percentage', 'LIKE', (array)"%$new_spent_time->daily_percentage%", $fromDate);
        $request['percentage'] = (int)$new_spent_time->percentage + $spent_time->daily_percentage;
        $new_spent_time->save();

        return $spent_time->update($data);
    }
}

person Lia nur fadilah    schedule 18.10.2018    source источник


Ответы (2)


$task_category находится внутри массива "%$task_category%"?

Если это так, это вызывает ошибку, потому что массив не может быть помещен в %.

Это может быть решением для laravelc Как и со значением массива< /а>


person jj40308    schedule 18.10.2018

Вы не можете вернуть обновленный запрос, поэтому попробуйте

return $spent_time->fresh();

а затем ошибка сохраняется добавить как

return $spent_time->fresh()->toArray();
person Jayashree    schedule 19.10.2018
comment
@Lianurfadilah Я не могу тебя достать? Так ты можешь мне объяснить - person Jayashree; 22.10.2018
comment
вы можете увидеть stackoverflow.com/questions/52889490/ - person Lia nur fadilah; 22.10.2018
comment
stackoverflow.com/questions/52922240/ - person Lia nur fadilah; 22.10.2018
comment
Измените toArray() на метод toJson() - person Jayashree; 22.10.2018
comment
Попробуйте вернуть response()-›json($spent_time-›fresh()-›toArray()); - person Jayashree; 22.10.2018
comment
до сих пор нет изменений - person Lia nur fadilah; 22.10.2018