dimanche 31 janvier 2016

MethodNotAllowedHttpException error in Laravel 5 using ajax

I am trying to upload an image with ajax and i am getting: Failed to load resource: the server responded with a status of 500 (Internal Server Error). Here is my ajax:

$('document').ready(function() {
    $('#uploadImage').change(function(){
        image = $('#uploadImage').val;
        token = $('#token').val();
        $.ajax ({
            type: 'POST',
            url: '/photo',
            data: { image , token },
            success: function(){

                $('.img-thumbnail').attr("src", 'images/new_image.png');
            }
        })
    })


});

Here is my route: Route::post('/photo', 'ShopsController@uploadPhoto');

This is my controller:

public function uploadPhoto(Request $request)
    {

        //Sets file name according to authenticated shop id
        $imageName = 'new_image.png';

        //Save file to public/images

        $img = Image::make($request->file('image'));
     $img->resize(380, 300)->save('images/' . $imageName, 60);
    }

And this is my form:

<form action="{{ action('ShopsController@store') }}" method="post" enctype="multipart/form-data">
    <input id="token" type="hidden" name="_token" value="{{ csrf_token() }}">
   <input id="uploadImage" class="btn btn-upload" type="file" name="image"> </form>



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1KjD6ha
via IFTTT

Aucun commentaire:

Enregistrer un commentaire