invoices/index.blade.php
<td>
<form action="{{url('/invoice_status_upadated')}}" method="POST">
{{ csrf_field() }}
<div >
<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" >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', 'App\Http\Controllers\TemplateController@invoice_status_upadated')->name('invoice_status_upadated');
View
error
CodePudding user response:
Instead of doing $data->status=$request->$data->status;
do $data->status = $request->status;
$request does not have the data from the model, which is in the $data variable.
CodePudding user response:
Try this :
<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.
CodePudding user response:
Hi first of all you need to async you select tag with name tag and set it to status for example
<select aria-label="Default select example" name="status">
<input type="hidden" value="{{ $inv->id }}" name="inv_id"/>
then in your controller first of all you need to validate your request incomping data for mor information please see this in laravel documentations
after that you need to change your code like this
$data= Invoice::find($request->inv_id);
$data->status= $data->status;