you can't do that with a request object. it contains far more than just your data.
extract the data from the request, then check if its an array.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a task list app with Vuejs + Laravel. I want to be able to do an ajax post request to store multiple tasks at once.
My code for posting 1 task works like below, but when making an array of it and doing an "insert" instead of "create" on the DB it crashes.
Workflow for 1 task:
##Ajax request:
this.$http.post('/api/items',newItem) // newItem is an object
##Ajax Controller:
public function store(Request $request)
{
return Item::create($request->all());
}
Now I tried with an array of newItems instead:
newItemArray = [newItemA, newItemB];
this.$http.post('/api/items',newItemArray) // send array
public function store(Request $request)
{
if (is_array ($request->all())){
return Item::insert($request->all());
}
return Item::create($request->all());
}
But I get the following bug:
UnexpectedValueException in Response.php line 399: The Response content must be a string or object implementing __toString(), "boolean" given.
Obviously I cannot send an array it seems.
How can I send an array through Ajax and do a big "insert" into the DB?
Please or to participate in this conversation.