this is the blade, where i am trying to change the status from 1 to 2 with onchange method
<td>
<form method="post" action="/update-status/{{ $cars->id }}">
{{ csrf_field() }}
<select class="form-control" onchange="this.form.submit();">
<option value="1" {{ ($cars->status) == 1 ? 'selected' : null }}>למכירה</option>
<option value="2" {{ ($cars->status) == 2 ? 'selected' : null }}>נמכר</option>
</select>
</form>
</td>
this is the controller
public function updateStatus(Request $request,Car $cars)
{
$cars->update($request->all());
return redirect('cars-list' );
}
this is the route
Route::post('/update-status/{cars}', 'HomeController@updateStatus');
I'm assuming that you want to toggle between status 1 & 2, so change your blade code to this
<td>
<form method="post" action="/update-status/{{ $cars->id }}">
{{ csrf_field() }}
<select class="form-control" onchange="this.form.submit();" name="status">
<option value="1" @if(($cars->status) == 1) selected @endif>למכירה</option>
<option value="2" @if(($cars->status) == 2) selected @endif>נמכר</option>
</select>
</form>
</td>
and change your controller to this:
public function updateStatus(Request $request,$cars){
$cars = Cars::find($cars);
if($cars->status == 1){
$cars->status = 1;
}
else{
$cars->status = 2;
}
$cars->save();
return redirect('cars-list');
}
Let me know if it's helpful
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.