-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiamondPackController.php
More file actions
141 lines (122 loc) · 4.59 KB
/
DiamondPackController.php
File metadata and controls
141 lines (122 loc) · 4.59 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
namespace App\Http\Controllers;
use App\Models\DiamondPacks;
use Illuminate\Http\Request;
class DiamondPackController extends Controller
{
//
function diamondpacks()
{
return view('diamondpacks');
}
function getDiamondPacks(Request $request){
$data = DiamondPacks::all();
return json_encode([
'status' => true,
'message' => 'diamond packs get successfully',
'data' => $data
]);
}
public function addDiamondPack(Request $request)
{
$pack = new DiamondPacks();
$pack->amount = $request->amount;
$pack->android_product_id = $request->android_product_id;
$pack->ios_product_id = $request->ios_product_id;
$pack->save();
return response()->json([
'status' => true,
'message' => 'Diamond Pack Added Successfully',
]);
}
function getDiamondPackById($id)
{
$data = DiamondPacks::where('id', $id)->first();
echo response()->json($data);
}
function updateDiamondPack(Request $request)
{
$pack = DiamondPacks::where('id', $request->id)->first();
$pack->amount = $request->amount;
$pack->android_product_id = $request->android_product_id;
$pack->ios_product_id = $request->ios_product_id;
$pack->save();
return response()->json([
'status' => true,
'message' => 'Diamond Pack Updated Successfully',
]);
}
function deleteDiamondPack(Request $request)
{
$diamondPack = DiamondPacks::where('id', $request->diamond_pack_id)->first();
$diamondPack->delete();
return response()->json([
'status' => true,
'message' => 'Diamond Pack Deleted',
]);
}
function fetchDiamondPackages(Request $request)
{
$totalData = DiamondPacks::count();
$rows = DiamondPacks::orderBy('id', 'DESC')->get();
$result = $rows;
$columns = array(
0 => 'id',
1 => 'amount'
);
$limit = $request->input('length');
$start = $request->input('start');
$order = $columns[$request->input('order.0.column')];
$dir = $request->input('order.0.dir');
$totalData = DiamondPacks::count();
$totalFiltered = $totalData;
if (empty($request->input('search.value'))) {
$result = DiamondPacks::offset($start)
->limit($limit)
->orderBy($order, $dir)
->get();
} else {
$search = $request->input('search.value');
$result = DiamondPacks::Where('amount', 'LIKE', "%{$search}%")
->orWhere('android_product_id', 'LIKE', "%{$search}%")
->orWhere('ios_product_id', 'LIKE', "%{$search}%")
->offset($start)
->limit($limit)
->orderBy($order, $dir)
->get();
$totalFiltered = DiamondPacks::where('amount', 'LIKE', "%{$search}%")
->orWhere('android_product_id', 'LIKE', "%{$search}%")
->orWhere('ios_product_id', 'LIKE', "%{$search}%")
->count();
}
$data = array();
foreach ($result as $item) {
$block = '<span class="float-end">
<a href="" rel="' . $item->id . '"
class="btn btn-success edit mr-2"
data-amount="'. $item->amount .'"
data-android_product_id="'. $item->android_product_id .'"
data-ios_product_id="'. $item->ios_product_id .'">
Edit
</a>
<a rel="'.$item->id.'" class="btn btn-danger delete text-white">
Delete
</a>
</span>';
$data[] = array(
$item->amount,
$item->android_product_id,
$item->ios_product_id,
$block
);
}
$json_data = array(
"draw" => intval($request->input('draw')),
"recordsTotal" => intval($totalData),
"recordsFiltered" => $totalFiltered,
"data" => $data
);
echo json_encode($json_data);
exit();
}
}