0
votes

Blog - RESTful Resource Controller

route to the controller Blog

Route::resource('blog', 'BlogController');

Simple query does not work

$http.delete('/blog/1');

return

403 Forbidden

POST(store), GET (index, show), requests work

delete (destroy) does not work

$http.post('/blog/1', {_method: 'DELETE'});

return

405 Method Not Allowed

<?php

class BlogController extends \BaseController {

    public function index()
    {
        return Blog::orderBy('id')->get();
    }

    public function store()
    {
        ....
        ....
    }

    public function edit($id)
    {
        return Blog::find($id);
    }

    public function destroy($id)
    {
        Blog::destroy($id);
    }


}
1
can you post your controller fileworldask
Is that API and the APP on the same domain ? or are you performing a Cross Origin RequestLinial
Check your network tab for the request headers section to see what it's sending exactly, is the method actual being set as DELETE. I've used $resource with a Slim PHP backend and it's worked out fine using .$delete on items pulled from the server, if the default setup doesn't work you can customize what is sent like $http({'method':'DELETE', url:'/blog/1'}) typically a $resource works well with RESTful CRUD though.shaunhusain
403 Forbidden c2n.me/j5xqwOSergio

1 Answers

1
votes

Some web servers may block http delete method. if you use Apache, try to allow it. Add this code to your .htaccess file:

<Limit GET POST DELETE>
  Allow from all
</Limit>

Similar problem was posted here

Hope this helps :)