0

I need to be able to change objects on server, save those, and return results back to frontend part of application. So basically, I have some code that does manipulation of data, than Eloquent that does saving, and than I want to return Eloquent object back. Problem is that I have more than one object, that I'll manipulate, and right now, I'm putting all of them in array. When it comes back to my frontend all it has is this:

[{"incrementing":true,"timestamps":true,"exists":true}]

Here is the simplified code:

$results = array();
foreach ($tasks as $task){
 //some manipulation
 $result = Task::find($task['id']);
 $result->order = $task['order'];
 $result->save();
 $results[] = $result;
}
return Response::json($results);

1 Answer 1

1

Ok, the solution was to call toArray() method before putting element to array.

$results[] = $result->toArray();
Sign up to request clarification or add additional context in comments.

1 Comment

I had a similar situation, now it works. Still, the solution is kind of dirty and not laravel-conform. I thought it should be better to solve it with a Eloquent Collection, but didn't work well too. Probably this is something they should fix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.