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

421
Views
¿Laravel no puede cambiar mi estado en mi base de datos usando el botón de alternar?

Estoy usando un interruptor de botón de palanca:

 <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>

Aquí está mi script con el 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>

Aquí está mi código web.php:

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

Luego mi SupAdController.php:

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

Se puede hacer clic en el botón de alternar, pero el estado de la base de datos no cambiará.

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!