|
2
|
1 <?php
|
|
|
2
|
|
|
3 namespace App\Http\Controllers;
|
|
|
4
|
|
|
5 use App\Http\Requests\Client\FilterClientRequest;
|
|
|
6 use App\Http\Requests\Client\StoreClientRequest;
|
|
|
7 use App\Http\Requests\Client\UpdateClientRequest;
|
|
|
8 use App\Models\Client;
|
|
|
9
|
|
|
10 class ClientController extends Controller
|
|
|
11 {
|
|
|
12 /**
|
|
|
13 * Display a listing of the resource.
|
|
|
14 *
|
|
|
15 * @return \Illuminate\View\View
|
|
|
16 */
|
|
|
17 public function index(FilterClientRequest $request)
|
|
|
18 {
|
|
|
19 $validated = $request->validated();
|
|
|
20 $data = [];
|
|
|
21 $data['items'] = Client::get_data($validated);
|
|
|
22 $data = array_merge($data, Client::load_index());
|
|
|
23
|
|
|
24 return view('clients.index', $data);
|
|
|
25 }
|
|
|
26
|
|
|
27 public function get_data()
|
|
|
28 {
|
|
|
29 $data = [];
|
|
|
30 $data['records'] = Client::get_data([]);
|
|
|
31 $data['total_records'] = count($data['records']);
|
|
|
32
|
|
|
33 return $data;
|
|
|
34 }
|
|
|
35
|
|
|
36 /**
|
|
|
37 * Show the form for creating a new resource.
|
|
|
38 *
|
|
|
39 * @return \Illuminate\View\View
|
|
|
40 */
|
|
|
41 public function create()
|
|
|
42 {
|
|
|
43 $data = [];
|
|
|
44 $data = array_merge($data, Client::load_create());
|
|
|
45
|
|
|
46 return view('clients.create_edit', $data);
|
|
|
47 }
|
|
|
48
|
|
|
49 /**
|
|
|
50 * Store a newly created resource in storage.
|
|
|
51 *
|
|
|
52 * @return \Illuminate\Http\RedirectResponse
|
|
|
53 */
|
|
|
54 public function store(StoreClientRequest $request)
|
|
|
55 {
|
|
|
56 $validated = $request->validated();
|
|
|
57
|
|
|
58 Client::create($validated);
|
|
|
59
|
|
|
60 return redirect()->route('clients.index');
|
|
|
61 }
|
|
|
62
|
|
|
63 /**
|
|
|
64 * Display the specified resource.
|
|
|
65 *
|
|
|
66 * @return \Illuminate\View\View
|
|
|
67 */
|
|
|
68 public function show(Client $client)
|
|
|
69 {
|
|
|
70 $data = [];
|
|
|
71 $data['item'] = $client;
|
|
|
72 $data['fields'] = (new Client)->getFillable();
|
|
|
73
|
|
|
74 return view('clients.show', $data);
|
|
|
75 }
|
|
|
76
|
|
|
77 /**
|
|
|
78 * Returns the resource in JSON format.
|
|
|
79 *
|
|
|
80 * @param ModelType $modelVariable
|
|
|
81 * @return string
|
|
|
82 */
|
|
|
83 public function load(Client $client)
|
|
|
84 {
|
|
|
85 return $client->toJson();
|
|
|
86 }
|
|
|
87
|
|
|
88 /**
|
|
|
89 * Show the form for editing the specified resource.
|
|
|
90 *
|
|
|
91 * @return \Illuminate\View\View
|
|
|
92 */
|
|
|
93 public function edit(Client $client)
|
|
|
94 {
|
|
|
95 $data = [];
|
|
|
96 $data['item'] = $client;
|
|
|
97
|
|
|
98 // Load data for relationships
|
|
|
99 $data = array_merge($data, Client::load_edit());
|
|
|
100
|
|
|
101 return view('clients.create_edit', $data);
|
|
|
102 }
|
|
|
103
|
|
|
104 /**
|
|
|
105 * Update the specified resource in storage.
|
|
|
106 *
|
|
|
107 * @return \Illuminate\Http\RedirectResponse
|
|
|
108 */
|
|
|
109 public function update(UpdateClientRequest $request, Client $client)
|
|
|
110 {
|
|
|
111 $validated = $request->validated();
|
|
|
112
|
|
|
113 $client->update($validated);
|
|
|
114
|
|
|
115 return redirect()->route('clients.index');
|
|
|
116 }
|
|
|
117
|
|
|
118 /**
|
|
|
119 * Remove the specified resource from storage.
|
|
|
120 *
|
|
|
121 * @return \Illuminate\Http\RedirectResponse
|
|
|
122 */
|
|
|
123 public function destroy(Client $client)
|
|
|
124 {
|
|
|
125 $client->delete();
|
|
|
126
|
|
|
127 return redirect()->route('clients.index');
|
|
|
128 }
|
|
|
129 }
|