Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

asaketr64x's avatar

Why laravel is showing null when I am sending a formdata request from Vuejs?

I am using the vue2-editor library.When I upload an image , I create a formdata and append the uploaded image to it . But when I send this form data to server it shows null!

The vue js code



 handleImageAdded(file, editor, cursorLocation, resetUploader) {
        let formdata = new FormData();
        formdata.append("image", file);
        axios.post('/upload/answer/image', {
            formdata
          })
          .then(response => {
            console.log(response.data);
          });

      }
    

The laravel code

Route::post('/upload/answer/image', function (Request $request) {
    dd($request->all());
});

The above code shows null! However the below code works


    
 handleImageAdded(file, editor, cursorLocation, resetUploader) {
        let formdata = new FormData();
        formdata.append("image", file);
        console.log(formdata.get("image");

      }

This means that there is something fishy in laravel side.What should I do? Note: I am following the exact same steps as shown here

0 likes
8 replies
rin4ik's avatar
rin4ik
Best Answer
Level 50

first of all try to console.log your formdata before making the request

  axios.post('/upload/answer/image', formdata)
          .then(response => {
            console.log(response.data);
          });
Route::post('/upload/answer/image', function (Request $request) {
 $request->file('image')
});
asaketr64x's avatar

Yes I did see the last codeblock I uploaded . Its working.Its not showing null!!!

asaketr64x's avatar

That was a FATAL MISTAKE!!.....thanks for the help

asaketr64x's avatar

The probelm was in this line

//The correct way
axios.post('/upload/answer/image', formdata)
//My mistake
axios.post('/upload/answer/image', {
formdata
})
1 like

Please or to participate in this conversation.