how to make toggel button for active and unactive status
@jukia you can achieve it via jS easily. But you can also use laravel.
In the blade:
<form method="POST" action="{{ route('items.update', $item->id) }}">
@csrf
@method('PATCH')
<label for="status">Status:</label>
<input type="checkbox" name="status" id="status" {{ $item->status ? 'checked' : '' }}>
<button type="submit">Save</button>
</form>
In the controller:
public function update(Request $request, $id)
{
$item = Item::findOrFail($id);
$item->status = $request->has('status');
$item->save();
return redirect()->back()->with('success', 'Status updated successfully.');
}
@saurabhd i have seen this very logn time ago but it is not working so please guide me where is the problem in this code
@jukia show your code so i can suggest.
@saurabhd all the above code you mention i just copy paste
@jukia problem with copy and paste.... you learn nothing.
<form action="{{ route('change.status') }}">
@csrf
<input type="hidden" id="status" name="status" value="Active">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" name="switch" checked role="switch" id="flexSwitchCheckDefault">
</div>
</form>
$("#flexSwitchCheckDefault").change(function(e) {
if ($(this).prop('checked') == false) {
console.log("inactive");
$('#status').val("Inactive")
//or you can call ajax
} else if ($(this).prop('checked') == true) {
$('#status').val("Active")
//or you can call ajax
}
});
Route::post('status_update',[AuthController::class,'status_update'])->name('change.status');
public function status(Request $request)
{
$item = new Table()
$item->status = $request->status;
$item->save();
return redirect()->back()->with('success', 'Status updated successfully.');
}
SELECT COUNT(status)
FROM acquires where status="rejected"
Please or to participate in this conversation.