-1

I'm trying to use my Api to delete an object, I'm using restangular so here is how I do my request :

function destroy( resource )
{
    clear( this.cache );
    return this.restangular.one(this.route, resource.uuid).remove();
}

TmService.destroy(tmToDelete.id)

The request is good, all other ones works (get request), but this one I have the error DELETE ... (Method not allowed).

I think this problem comes from my header, but in the Api I already put this :

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods:  POST, GET, OPTIONS, PUT, PATCH, DELETE');
header('Access-Control-Allow-Headers:  Content-Type, X-Auth-Token, Origin, Authorization, X-HTTP-Method-Override');

What can I do ?

Edit:

here is my routes :

Route::resource('/tm', 'TmController');

And with artisan route:list :

enter image description here

Spialdor
  • 1,475
  • 5
  • 20
  • 46

1 Answers1

1

I've also encountered this issue previously. This is not actually the issue with laravel or request mechanism at all but the issue with client side i.e. browser. The simple hack is you call post method but with extra formParams in it.

<input type="hidden" name="_method" value="DELETE" />

Now laravel will understand that the request type is DELETE.

Updated*

I actually don't know how you are implementing restangular. But following is the simple way of passing extra param. Laravel understands the following request as delete request as it finds _method property and Delete value:

let data = {_method: 'DELETE'}
TmService.post(data);
Yubaraj Shrestha
  • 864
  • 1
  • 10
  • 16