Mercurial > packages > magicforger
annotate src/Generator/Controller/stubs/controller.stub @ 32:45f384a24553 codex
Support for server side tables
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Tue, 19 Aug 2025 22:15:50 -0400 |
| parents | 010ace248d14 |
| children |
| rev | line source |
|---|---|
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
1 <?php |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
2 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
3 namespace {{ namespace }}; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
4 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
5 use {{ namespacedModel }}; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
6 use {{ rootNamespace }}Http\Controllers\Controller; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
7 {{ requestUses }} |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
8 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
9 class {{ class }} extends Controller |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
10 { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
11 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
12 * Display a listing of the resource. |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
13 * |
|
29
010ace248d14
Added support for filters, not fully there with relations or anything like that but it's a start
Luka Sitas <sitas.luka.97@gmail.com>
parents:
27
diff
changeset
|
14 * @param {{ filterRequest }} $request |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
15 * @return \Illuminate\View\View |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
16 */ |
|
29
010ace248d14
Added support for filters, not fully there with relations or anything like that but it's a start
Luka Sitas <sitas.luka.97@gmail.com>
parents:
27
diff
changeset
|
17 public function index({{ filterRequest }} $request) |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
18 { |
|
29
010ace248d14
Added support for filters, not fully there with relations or anything like that but it's a start
Luka Sitas <sitas.luka.97@gmail.com>
parents:
27
diff
changeset
|
19 $validated = $request->validated(); |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
20 $data = []; |
|
29
010ace248d14
Added support for filters, not fully there with relations or anything like that but it's a start
Luka Sitas <sitas.luka.97@gmail.com>
parents:
27
diff
changeset
|
21 $data['items'] = {{ model }}::get_data($validated); |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
22 $data = array_merge($data, {{ model }}::load_index()); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
23 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
24 return view('{{ tableName }}.index', $data); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
25 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
26 |
|
32
45f384a24553
Support for server side tables
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
27 public function get_data() |
|
45f384a24553
Support for server side tables
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
28 { |
|
45f384a24553
Support for server side tables
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
29 $data = []; |
|
45f384a24553
Support for server side tables
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
30 $data['records'] = {{ model }}::get_data([]); |
|
45f384a24553
Support for server side tables
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
31 $data['total_records'] = count($data['records']); |
|
45f384a24553
Support for server side tables
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
32 |
|
45f384a24553
Support for server side tables
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
33 return $data; |
|
45f384a24553
Support for server side tables
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
34 } |
|
45f384a24553
Support for server side tables
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
35 |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
36 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
37 * Show the form for creating a new resource. |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
38 * |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
39 * @return \Illuminate\View\View |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
40 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
41 public function create() |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
42 { |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
43 $data = []; |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
44 $data = array_merge($data, {{ model }}::load_create()); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
45 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
46 return view('{{ tableName }}.create_edit', $data); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
47 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
48 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
49 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
50 * Store a newly created resource in storage. |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
51 * |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
52 * @param {{ storeRequest }} $request |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
53 * @return \Illuminate\Http\RedirectResponse |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
54 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
55 public function store({{ storeRequest }} $request) |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
56 { |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
57 $validated = $request->validated(); |
| 5 | 58 |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
59 {{ model }}::create($validated); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
60 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
61 return redirect()->route('{{ tableName }}.index'); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
62 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
63 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
64 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
65 * Display the specified resource. |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
66 * |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
67 * @param {{ model }} ${{ modelVariable }} |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
68 * @return \Illuminate\View\View |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
69 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
70 public function show({{ model }} ${{ modelVariable }}) |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
71 { |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
72 $data = []; |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
73 $data['item'] = ${{ modelVariable }}; |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
74 $data['fields'] = (new {{ model }}())->getFillable(); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
75 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
76 return view('{{ tableName }}.show', $data); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
77 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
78 |
|
27
b17f81b804ff
Added support for routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
79 /** |
|
b17f81b804ff
Added support for routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
80 * Returns the resource in JSON format. |
|
b17f81b804ff
Added support for routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
81 * |
|
b17f81b804ff
Added support for routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
82 * @param ModelType $modelVariable |
|
b17f81b804ff
Added support for routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
83 * @return string |
|
b17f81b804ff
Added support for routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
84 */ |
|
b17f81b804ff
Added support for routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
85 public function load({{ model }} ${{ modelVariable }}) |
|
b17f81b804ff
Added support for routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
86 { |
|
b17f81b804ff
Added support for routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
87 return ${{ modelVariable }}->toJson(); |
|
b17f81b804ff
Added support for routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
88 } |
|
b17f81b804ff
Added support for routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
89 |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
90 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
91 * Show the form for editing the specified resource. |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
92 * |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
93 * @param {{ model }} ${{ modelVariable }} |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
94 * @return \Illuminate\View\View |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
95 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
96 public function edit({{ model }} ${{ modelVariable }}) |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
97 { |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
98 $data = []; |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
99 $data['item'] = ${{ modelVariable }}; |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
100 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
101 // Load data for relationships |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
102 $data = array_merge($data, {{ model }}::load_edit()); |
|
15
f19c023bda04
Updated the Controller stub
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
103 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
104 return view('{{ tableName }}.create_edit', $data); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
105 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
106 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
107 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
108 * Update the specified resource in storage. |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
109 * |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
110 * @param {{ updateRequest }} $request |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
111 * @param {{ model }} ${{ modelVariable }} |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
112 * @return \Illuminate\Http\RedirectResponse |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
113 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
114 public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }}) |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
115 { |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
116 $validated = $request->validated(); |
| 5 | 117 |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
118 ${{ modelVariable }}->update($validated); |
| 5 | 119 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
120 return redirect()->route('{{ tableName }}.index'); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
121 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
122 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
123 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
124 * Remove the specified resource from storage. |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
125 * |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
126 * @param {{ model }} ${{ modelVariable }} |
|
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
127 * @return \Illuminate\Http\RedirectResponse |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
128 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
129 public function destroy({{ model }} ${{ modelVariable }}) |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
130 { |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
131 ${{ modelVariable }}->delete(); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
132 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
15
diff
changeset
|
133 return redirect()->route('{{ tableName }}.index'); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
134 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
135 } |
