"Unexpected data found" on function return

Asked

Viewed 25 times

0

I have a function that should return a json from a Collection generated by a Builder query.

    $today = Carbon::today()->format('Y-m-d');
    $tasks = Task::where('date', $today)->whereHas('collaborators', function($q) {

        $q->where('collaborator_id', '=', Auth::user()->id)
        ->where('allocation', '=', 1)
        ->where('accepted', '=', 1)
        ->where('confirm_allocation', '=', 1);

    })->with('event')->get();

However whenever I try to return the result with:

    return response()->json($tasks, 200);

I get an error "Unexpected data found"

inserir a descrição da imagem aqui

When doing a Dump and Die in the $tasks variable returns me the expected results.

inserir a descrição da imagem aqui

That is, the return of json is gives rise to the error "Unexpected data found". If I remove the relation of the query, ie with('Event'), the results are already returned correctly and in json format, but I even need the relation to be returned too.

1 answer

0

I removed from the Model Event

protected $dateFormat = 'Y-m-d H:i:s';
protected $dates = ['date_time_init', 'date_time_end'];

These lines of code conflicted with

public function getDateTimeInitAttribute($value)
{
    return $this->attributes['date_time_init'] = Carbon::parse($value)->format('d-m-Y H:i');
}

public function getDateTimeEndAttribute($value)
{
    return $this->attributes['date_time_end'] = Carbon::parse($value)->format('d-m-Y H:i');
}

public function setDateTimeInitAttribute($value)
{
    return $this->attributes['date_time_init'] = Carbon::parse($value)->format('Y-m-d H:i:s');
}

public function setDateTimeEndAttribute($value)
{
    return $this->attributes['date_time_end'] = Carbon::parse($value)->format('Y-m-d H:i:s');
}

public function setCreatedAtAttribute($value)
{
    return $this->attributes['created_at'] = Carbon::parse($value);
}

public function setUpdatedAtAttribute($value)
{
    return $this->attributes['updated_at'] = Carbon::parse($value);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.