-1

I'm currently making a membership system in Laravel where the admin needs to approve a user for it to be able to login to the system.

How can I update a status to 'approved' with a single-click from a button?

I know this might seem easy to most of developers, I only started web development about 2 weeks ago. I would really appreciate your help :)

1 Answers1

1

This is very basic and your question is incomplete.

first, you need a button for approval (maybe in a @foreach block)

<a onclick="approve(<row id>)" class="your_button_class">Click to Approve!</a>

then you need a script

<script>
 function approve(id)
 {
   $.ajax({
      //some ajax call to deal with your approve link
      type: 'post',
            url: 'route to update data',
            data: "id="+id,
            success: function (data) { 
                alert('updated');
            }
   });
 }
</script>

In your controller

function update(Request $request)
{
 $id=$request->id;
 $model = new YourModel();
 //assumed your column is "approved" and approved status is "0"
 $updated = $model->find($id)->update(['approved'=>1]);
 return $updated;
}

use this reference to build your logic. or see this example

Unni K S
  • 365
  • 4
  • 15