update field using ajax in laravel giving 500 error

Viewed 33

i am trying to update the status on a button click using ajax in laravel my view file below

 @if($product->status =='0')
    <td>
      <button type="button" data-id="{{ $product->user_id }}" class="btn btn-success active_btn">active</button>
    </td>
  @else
    <td>
      <button type="button" data-id="{{ $product->user_id }}" class="btn btn-danger  deactive_btn">Deactive</button>
    </td>
  @endif

the ajax code i have provided here

$(document).on('click', '.active_btn', function(e) {
      e.preventDefault();
      let id = $(this).data('id');
      $.ajax({
        url: '{{ route("invetory.update") }}',
        method: 'PUT',
        data: {
          id: id,
          status: 1,
          _token: '{{ csrf_token() }}'
        },
        success: function(response) {
          console.log(response);
        }
      });
    });


web.php

Route::post('/update', 'App\Http\Controllers\InventoryController@update')>name('invetory.update');

InventoryController.php

public function update(Request $REQUEST){
  dd($REQUEST->all());
  
       Inventory::update( $REQUEST->invetory as $key => $value);
 
    return redirect()->action([InventoryController::class, 'index']);
}

I am getting 500 error

0 Answers
Related