2

with this url http://localhost:8888/api/v1/apartments/delete , I'm trying to delete a determinate apartment without passing the id through the URL. I'm sending data with POSTMAN but I can't catch it with Request or Input classes.

Routes.php

Route::delete('/api/v1/apartments/delete', 'ApartmentApiController@destroy');

ApartmentApiController

public function destroy(Request $request)
{
  dd($request->all());
}

enter image description here

In methods like UPDATE Request is working but not here in DELETE. Why is this? I'm a little bit curious and I have not found it.

It's a good practice to delete passing the item id in the URL like this? Should I do like this? http://localhost:8888/api/v1/apartments/delete/13

therealbigpepe
  • 1,489
  • 2
  • 16
  • 23
  • It is best practice not only to have the `id` in the URL when deleting (easier to find what happened from logs when you delete the wrong things) but also to require some kind of confirmation when deleting any database object (it prevents the deletion of items through XSS). – grochmal Jun 07 '16 at 19:40
  • Just a sidenote, I've had issues with postman and Laravel; Sending data through the actual post route would work, but performing a post request with postman would not. Eventually had to switch to a different REST client; possible you're experiencing this too, but hard to say for sure. – Tim Lewis Jun 07 '16 at 20:15
  • @grochmal it's all secured with JWT, but thanks for the advice. – therealbigpepe Jun 07 '16 at 22:30

2 Answers2

0

Since you are passing the id in the route:

Route::delete('apartments/delete/{id}', 'ApartmentApiController@destroy');

You need to inject that in your method along with the Request object.

public function destroy($id, Request $request)
{
  dd($id);
}
Angad Dubey
  • 5,067
  • 7
  • 30
  • 51
0

Just ran into this same problem. I found that I had to change the header from Accept: application/json to content-type: application/json...