Why are you appending ?_method=PUT?
Why not just set it as method: 'put' ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
My app runs fine locally. I can create and add cards with pictures.
Now I try to deploy the app ( first time I deploy a complete self made application...). Probably I made a basic mistake. Just cannot figure out what it is...
Trying to update a card, server generates a 405 error message : The server returned a "405 Method Not Allowed".
Request URL: http://sub.site.nl/api/cards/7?_method=PUT
Request Method: POST
Status Code: 405 Method Not Allowed
Remote Address: 185.224.89.43:80
Referrer Policy: strict-origin-when-cross-origin
Access-Control-Allow-Origin: *
allow: GET, HEAD, PUT, DELETE
Cache-Control: no-cache, private
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
date: Thu, 30 Dec 2021 13:04:51 GMT
Server: nginx/1.14.0 (Ubuntu)
Transfer-Encoding: chunked
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Content-Length: 540
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary62CtE2tIzeHJ1iNk
Cookie: XSRF-TOKEN=eyJpd...
Host: sub.site.nl
Origin: http://sub.site.nl
Referer: http://sub.site.nl/aanmelden
User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Mobile Safari/537.36
My routes were:
Route::apiResource('/cards', 'App\Http\Controllers\CardController');
changed them into, without success...
Route::get('/cards', 'App\Http\Controllers\CardController@index');
Route::post('/cards', 'App\Http\Controllers\CardController@store');
Route::get('/cards/{id}', 'App\Http\Controllers\CardController@show');
Route::put('/cards/{id}', 'App\Http\Controllers\CardController@update');
Route::delete('/cards/{id}', 'App\Http\Controllers\CardController@destroy');
This is the vue component method calling the api:
editCard(){
const formData = new FormData();
formData.append('title',this.card.title);
formData.append('description',this.card.description);
formData.append('imagefile',this.selectedFile);
formData.append('speler_id', this.currentSpeler.speler.id);
formData.append('game_id', this.currentGame.id);
fetch(`api/cards/${this.card.id}?_method=PUT`, {
method: 'post',
body:formData,
})
//.then(res => res.formData())
.then(res => console.log(res))
.then(data => {
this.card.title='';
this.card.description='';
this.url='';
this.$refs.fileUpload.value=null;
this.showSpelerCards();
})
.catch(err => console.log(err));
},
On localhost with Xampp ( windows) everything works fine, on the VPS it fails. On server I get 405 error: Server is nginx on ubuntu.
Can any one see what might be the problem?
Please or to participate in this conversation.