0

I'm trying to make an update to my app but getting a Status Code:405 Method Not Allowed header

Here's my backbone.js code

UserModel = Backbone.Model.extend({
    url:'/user'
    ,initialize:function(attributes,options){
        this.fetch()

        this.set('isEmail',true)
        this.sync('update',this,{
            success:function(){
                console.log('sync',arguments)
            }
        })

    }
})

The relevant parts of my routes.php file

Route::resource('user','UserController');

I do have a UserContoller set up with an update method

public function update(){
    return 'x';
}
Aakil Fernandes
  • 6,274
  • 5
  • 29
  • 49

2 Answers2

1

If you use a resource controller in Laravel, the update method requires an id parameter:

public function update($id){ 

} 

Also check if you're correctly sending the PUT request with id on the model.

html_programmer
  • 14,612
  • 12
  • 59
  • 125
  • This was essentially the issue. I had to send a request to /user/{something} - which is a bit silly since I'm dealing with a model not a collection and the id is irrelevant. – Aakil Fernandes Aug 30 '14 at 20:30
0

The problem is in your web server which does not support PUT (and other http methods used for RESTful services)

Backbone.js has special support for this (using POST method which supported by all web servers), which you can enable with:

Backbone.emulateHTTP = true;

model.save();  // POST to "/collection/id", with "_method=PUT" + header.

If you want to work with a legacy web server that doesn't support Backbone's default REST/HTTP approach, you may choose to turn on Backbone.emulateHTTP. Setting this option will fake PUT, PATCH and DELETE requests with a HTTP POST, setting the X-HTTP-Method-Override header with the true method. If emulateJSON is also on, the true method will be passed as an additional _method parameter.

ServiceStack Backbone.Todos Delete 405 not allowed

Community
  • 1
  • 1
Eugene Glova
  • 1,523
  • 1
  • 9
  • 12