0

I can't figure out why this block of code only works on my localhost, in my production server the requests goes through and $request->input() returns an empty array but in my localhost it works perfectly fine. Both on version php7. Any thoughts ?

var formData = new FormData($('#postSliderFrm')[0]);

if(imagePicked)
    formData.append('file',imagePicked);

formData.append('_method', 'put');

$.ajax({
    type: 'PUT',
    url: '{{route('dashboard.admin.sliders.update', $slider->id)}}',
    data: formData,
    processData: false,
    contentType: false,
    success: function(data) {

    },
    error: function(data) {

    }
});

I've also tried adding

{!! method_field('put') !!}

inside my form but still no luck

Cerlin
  • 6,622
  • 1
  • 20
  • 28
  • Cos your localhost post max size is more than 2 MB i guess. By default apache handles data worth only of 2MB. – Cerlin Jan 06 '17 at 09:55
  • What kind of response do you get from the server? (browser console->network->click on the request; Or something along these lines depending on the browser you're using) – DevK Jan 06 '17 at 09:57

1 Answers1

2

Method not allowed when PUT used over AJAX for Laravel resource: Take a look at that, it might be better to use GET or more commonly POST to handle this, do you specifically NEED to use PUT?

Community
  • 1
  • 1
Kenziiee Flavius
  • 1,918
  • 4
  • 25
  • 57
  • The linked question here shows the answer. You need to [spoof a PUT request in Laravel](https://laravel.com/docs/5.2/routing#form-method-spoofing). Replace ` type: 'PUT',` with POST, and include `method_field('put')` as you have. – Don't Panic Jan 06 '17 at 10:38
  • 1
    I'm using PUT because I'm using Laravel's CRUD resource. Are there any difference performance-wise PUT vs POST ? – user3364008 Jan 06 '17 at 11:52
  • @user3364008 Theres plently of information about them on stackoverflow, heres a really good example -> **http://stackoverflow.com/questions/107390/whats-the-difference-between-a-post-and-a-put-http-request** – Kenziiee Flavius Jan 06 '17 at 11:53
  • @Don'tPanic wow thanks ! that fixed my problem ! can't believe the fix was that easy but it was strange that it worked on my localhost – user3364008 Jan 06 '17 at 11:54