|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use App\Http\Resources\DataTables\CustomerResource; |
|
7
|
|
|
use App\Models\Customer; |
|
8
|
|
|
use Illuminate\Http\Request; |
|
9
|
|
|
use Yajra\DataTables\Facades\DataTables; |
|
10
|
|
|
|
|
11
|
|
|
class CustomerController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Display a listing of the resource. |
|
15
|
|
|
* |
|
16
|
|
|
* @return \Illuminate\Contracts\Support\Renderable |
|
17
|
|
|
*/ |
|
18
|
|
|
public function index() |
|
19
|
|
|
{ |
|
20
|
|
|
return view('admin.customer.index'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Return datatable server side response. |
|
25
|
|
|
* |
|
26
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
27
|
|
|
*/ |
|
28
|
|
|
public function datatable() |
|
29
|
|
|
{ |
|
30
|
|
|
return DataTables::eloquent(Customer::query()) |
|
31
|
|
|
->setTransformer(fn ($model) => CustomerResource::make($model)->resolve()) |
|
32
|
|
|
->toJson(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Show the form for editing the specified resource. |
|
37
|
|
|
* |
|
38
|
|
|
* @param \App\Models\Customer $customer |
|
39
|
|
|
* @return \Illuminate\Contracts\Support\Renderable |
|
40
|
|
|
*/ |
|
41
|
|
|
public function edit(Customer $customer) |
|
42
|
|
|
{ |
|
43
|
|
|
return view('admin.customer.edit', compact('customer')); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Update the specified resource in storage. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \Illuminate\Http\Request $request |
|
50
|
|
|
* @param \App\Models\Customer $customer |
|
51
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
52
|
|
|
*/ |
|
53
|
|
|
public function update(Request $request, Customer $customer) |
|
54
|
|
|
{ |
|
55
|
|
|
$customer->update($request->all()); |
|
56
|
|
|
|
|
57
|
|
|
return redirect()->route('admin.customer.index'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Remove the specified resource from storage. |
|
62
|
|
|
* |
|
63
|
|
|
* @param \App\Models\Customer $customer |
|
64
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
65
|
|
|
*/ |
|
66
|
|
|
public function destroy(Customer $customer) |
|
67
|
|
|
{ |
|
68
|
|
|
$customer->delete(); |
|
69
|
|
|
|
|
70
|
|
|
return redirect()->route('admin.customer.index'); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|