dd($request->all());
Ok you fix it :D
This is how I make request from front
editDocument() {
this.$refs.form.validate();
let formData = new FormData();
formData.append('name', this.document.name);
formData.append('document', this.document.document);
formData.append('category', this.document.category);
formData.append('description', this.document.description);
formData.append('user_id', this.user.id);
axios.put('/api/documents/' + this.document.id, formData, {
headers: {'Content-Type': 'multipart/form-data'},
}).then(response => {
// this.$refs.form.reset();
// this.$router.push({name: 'all-docs'});
});
},
this is in api.php
Route::apiResource('documents', 'API\DocController');
this is code in the controller method
/**
* Update the specified resource in storage.
*
* @return void
*/
public function update(Request $request, Document $document)
{
dd($request->all());
}
$request->all() is showing an empty array. This is very strange.
Interestingly when I do $request->document it shows data from the database.
The thing is if there is a file (formData) in your request parameters, Request object can't see parameters when PUT or Patch methods is used. Workaround for this is to use post method. Kind of pity. https://github.com/laravel/framework/issues/13457
It would have been great if laravel would have thrown an error or warning because it is misleading and may take a lot of hours of debugging until someone finds out that it is php related bug.
Please or to participate in this conversation.