-
Notifications
You must be signed in to change notification settings - Fork 1
/
status_update_switcher.php
63 lines (42 loc) · 1.61 KB
/
status_update_switcher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!-- View -->
<label class="switch switch-primary">
<input class="switch-input status_change" type="checkbox"
{{ $brand->status == 1 ? 'checked' : '' }} data-flag='{{ $brand->status }}'
data-id="{{ $brand->id }}">
<span class="switch-track"></span>
<span class="switch-thumb"></span>
</label>
<!-- ajax -->
<script>
$('.status_change').change(function() {
var status = $(this).attr('data-flag');
var id = $(this).attr('data-id');
if (status == 1) {
status = 0;
} else {
status = 1;
}
$.ajax({
type: "post",
url: "{{ route('brand.status') }}",
data: {
"_token": "{{ csrf_token() }}",
"status": status,
"id": id
},
success: function(response) {
toastr.success(response.message);
}
});
});
</script>
<<?php
// Route
Route::post('brand/status', [BrandController::class, 'ajax_brand_list'])->name('brand.status');
//Contoller Method
public function ajax_brand_list(Request $request){
$brands = Brand::find($request->id);
$brands->status = $request->status;
$brands->save();
return response()->json(['status' => 'success', 'message' => 'Brand status updated successfully']);
}