Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

416
Views
Laravel cant change my status in my databse using the toggle button?

Im using a toggle button switch:

<td><input data-id="{{$user->id}}" class="toggle-class" type="checkbox" data-onstyle="success" data-offstyle="danger" data-toggle="toggle" data-on="Active" data-off="Inactive" {{ $user->statusBol ? 'checked' : '' }}></td>
       

Here is my script with the ajax:

<script>
$(function(){
    $('.toggle-class').change(function(){
        var statusUser = $(this).prop('checked') == true ? 1 : 0; //1 active, 0 inactive
        var user_id = $(this).data('id');
            $.ajax({
                type: "GET",
                dataType : "json",
                url: 'changeUserStatus',
                data : {'statusUser': statusUser, 'user_id': user_id},
                success: function(data){
                    console.log('Success')
                }
            });
    });
    });
</script>

Here is my web.php code:

Route::get('changeUserStatus', [SupAdController::class, 'changeUserStatus'])->name('changeUserStatus');

Then my SupAdController.php:

public function changeUserStatus(Request $request){
    $users = User::find($request->user_id);
    $users->statusBol = $request->statusUser;
    $users->save();
}

The toggle button can be clicked but the status on the database wont change.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!