annotate app/Http/Controllers/ClientController.php @ 2:90296614b7e2 default tip

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