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