Skip to content
Advertisement

I am beginner trying to update status on view table laravel but i am getting controller error that (Attempt to read property “status” on null)

invoices/index.blade.php

    <td>

                              <form action="{{url('/invoice_status_upadated')}}" method="POST">
                                
                                {{ csrf_field() }}
                                <div class="input-group mb-3">
                              <select class="form-select" aria-label="Default select example">
                                <option value="0" {{$inv->status == 0 ? 'selected':''}}>Pending </option>
                                <option value="1" {{$inv->status == 1 ? 'selected':''}}>In Process </option>
                                <option value="2" {{$inv->status == 2 ? 'selected':''}}>Completed </option>
                                <option value="3" {{$inv->status == 3 ? 'selected':''}}>Cancelled </option>
                                

                                  <?php 
                                  if ($inv->status == 0){
                                    echo "selected";
                                  }
                                    ?>
                                    
          
                                <?php 
                                if ($inv->status == 1){
          
                                  echo "selected";
                                }
                                
                                  ?>
                                 <?php 
                                 if ($inv->status == 2){
           
                                   echo "selected";
                                 }
                                 
                                   ?>                                         
                                <?php 
                                if ($inv->status == 3){
          
                                  echo "selected";
                                }
                                
                                  ?> 
                            
    
                            </select>
                            <button type="submit"  class="btn btn-outline-success">Update</button>

                            </div>
                              </form>

                            
                            </td> 

/TemplateContorller

public function invoice_status_upadated(Request $request){ 
    $data= Invoice::find($request->status);
    $data->status=$request->$data->status;
    $data->save();
    return redirect('invoices');
}

web.php

Route::post('/invoice_status_upadated', 'AppHttpControllersTemplateController@invoice_status_upadated')->name('invoice_status_upadated');

View

view for table

error

enter image description here

Advertisement

Answer

Try this :

<select class="form-select" aria-label="Default select example" name="status">

And also in your controller you have to change :-

$data = Invoice::find($invoice_id);
$data->status = $request->status;
$data->save();

Hope this will work for you.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement