0

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);
    }


}
4
  • can you post your controller file Commented Oct 14, 2014 at 16:41
  • Is that API and the APP on the same domain ? or are you performing a Cross Origin Request Commented Oct 14, 2014 at 17:09
  • 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. Commented Oct 14, 2014 at 18:49
  • 403 Forbidden c2n.me/j5xqwO Commented Oct 14, 2014 at 19:09

1 Answer 1

1

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.