Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jukia's avatar
Level 1

how to make toggel button for active and unactive status

in laravel

0 likes
10 replies
tisuchi's avatar

@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.');
}
jukia's avatar
Level 1

@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

SDCODE's avatar
<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.');
}
jukia's avatar
Level 1

SELECT COUNT(status) FROM acquires where status="rejected"

Please or to participate in this conversation.