Laravel, Ajax, Post updating

Posted 4 years ago by theUnforgiven

Hi all,

I'm a newbie when it comes to ajax and jQuery, but having a go at updating a row in my database on form submit which is returning a 500 Internal Server Error

Here's the form:

{{ Form::model($product, ['method' => 'PUT', 'route' => ['admin.products.update', $product->id], 'class' => 'form-horizontal','id' => 'editForm', 'files' => true]) }}

            Product Name
                     name }}">

            <div class="form-group">
            <div class="col-sm-2">Category</div>
                 <div class="col-lg-3">
                 <?php $selected_category = ($product->slug ?: null) ?>
                    {{ Form::select('category_id', $category, $selected_category, ['class' => 'form-control'])}}


            @foreach($options as $option)
               id }}" id="option_id">
                   size; ?>
                   {{ Form::select('size', $sizes, $selected_size, ['class' => 'form-control', 'id' => 'size'])}}

               colour; ?>
                   {{ Form::select('colour', $colours, $selected_colour, ['class' => 'form-control', 'id' => 'colour'])}}
                    stock }}" id="stock">

            <div class="form-group">
            <div class="col-sm-2">Status</div>
                 <div class="col-lg-3">
                  <?php $options = array('Inactive', 'Active'); ?>
                  {{ Form::select('status', $options, Input::old('status'), array('class' => 'form-control')) }}

            <div class="form-group">
                 <div class="col-lg-3">
                     <button class="btn btn-success">Update</button>

   {{ Form::close() }}

Here's the ajax

        var base_url = 'http://localhost';

            var option_id = $("input#option_id").val();
            var size = $("input#size").val();
            var colour = $("input#colour").val();
            var stock = $("input#stock").val();

            var dataString = 'size='+size+'&amp;optionID='+option_id+'&amp;stock='+stock+'&amp;colour='+colour;
                type: "POST",
                url : base_url + "/admin/updateProductOption",
                data : dataString,
                success : function(data){

 });//end of document ready function

here is the method to handle the update.

public function updateProductOption()
        $data = Input::all();
            $id = Input::get('id');
            $option = Options::where('id', $id)->first();
            $option->size = $data['size'];
            $option->colour = $data['colour'];
            $option->stock = $data['stock'];

But it's not updating and throwing a 500 error. Anyone have any idea's/advice help to give on this please ?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.