Or there is an error with thejson_encode/decode? Does it trigger if you add a dd after those?
$jsonDecode = json_decode($request);
$jsonData = json_encode($jsonDecode);
dd('hit');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I use the storage->put method to store a json file. This works as desired as follows:
Storage::disk('public_data')->put('test.json', $jsonData);
However, storage->put ignores all subsequent lines of code and even reloads the page, even if the post request was made asynchronously using ajax, as in my case.
Save file Methode:
public function create_json($request)
{
$jsonDecode = json_decode($request);
$jsonData = json_encode($jsonDecode);
Storage::disk('public_data')->put('test.json', $jsonData);
//this return will not run, because somehow Storage->put returns already
return "if you read this it was successful";
}
The POST request:
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector("#csrf-token").getAttribute('content')
},
body: JSON.stringify(data)
}).then(response => {
//this will never be reached
console.log(response);
})
I have read the storage documentation several times and could not find a sentence that would explain why this behavior occurs. Why is it that way?
TL;DR: storage->put ignores all subsequent lines of code and causes the frontend to reload. (Both should not be), why?
Please or to participate in this conversation.