Laravel 5.7 Toggle switch Update DB field using Ajax

Today, We want to share with you Laravel 5.7 Toggle switch Update DB field using Ajax.In this post we will show you Bootstrap Toggle Switch Inside Laravel Examples, hear for Use Ajax Checkbox Toggles To Update The Database we will give you demo and example for implement.In this post, we will learn about Bootstrap Toggle switch Update DB field using Ajax with Laravel 5.7 with an example.

Laravel 5.7 Toggle switch Update DB field using Ajax

There are the Following The simple About Laravel 5.7 Toggle switch Update DB field using Ajax Full Information With Example and source code.

  Bootstrap Toggle switch Update Database field using Ajax

As I will cover this Post with live Working example to develop php Laravel toggle switch with ajax update, so the Simple Laravel Toggle Switch Plugin With jQuery And Bootstrap for this example is following below.Demo – Laravel 5.7 toggle switch

Step 1: Laravel Create a Controller

Laravel – Toggle value in database with checkbox and ajax Example

public function updateProductStatus(Request $request)
{

    $member = User::findOrFail($request->member_id);
    if($member->active == 1){
        $member->active = 0;
    } else {
        $member->active = 1;
    }
    return response()->json([
      'data' => [
        'success' => $member->save(),
      ]
    ]);
}

Step 2: JavaScript Source Code

$(document).ready(function(){
  $("input:checkbox").change(function() {
    var member_id = $(this).closest('tr').attr('id');

    $.ajax({
            type:'POST',
            url:'/updateProductStatus',
            headers: {'X-CSRF-TOKEN': '{{ csrf_token() }}' },
            data: { "member_id" : member_id },
            success: function(data){
              if(data.data.success){
                //do something logic
              }
            }
        });
    });
});    

Related Keywords: laravel toggle button, Laravel 5.7 toggle switch, Laravel 5.7 toggle switch with text, Laravel 5.7 toggle switch, html toggle button, ajax toggle button php, Laravel 5.7 switch options, Laravel 5.7 toggle set value

  Laravel dynamic breadcrumbs with links
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.7 Toggle switch Update DB field using Ajax.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

avatar
  Subscribe  
Notify of