Level 70
Jun 17, 2022
7
Level 1
Laravel update user status using standard button
how to Update User Status Using standard button if you know pls say me a example
Level 1
@tisuchi me need standard button not toggle button
Level 70
@ArsenMK You are looking for an example. Why not you just try by inspiring this tutorial and raise your point then?
Level 1
@tisuchi I tried but it didn't work
Level 70
@ArsenMK Would you plz show your code?
Level 1
@tisuchi toggle button
<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->status ? 'checked' : '' }}>
</td>
script
<script>
$(function() {
$('.toggle-class').change(function() {
var status = $(this).prop('checked') == true ? 1 : 0;
var user_id = $(this).data('id');
$.ajax({
type: "GET",
dataType: "json",
url: '/status',
data: {'status': status, 'user_id': user_id},
success: function(data){
console.log(data.success)
}
});
})
})
</script>
controller
public function status(Request $request)
{
$user = User::find($request->user_id);
$user->status = $request->status;
$user->save();
return response()->json(['success'=>'человек успешно перемешен в раздел уволенные']);
}
Level 122
@ArsenMK console errors?
Do you have a route /status?
Please or to participate in this conversation.