annotate src/Generator/Controller/stubs/controller.stub @ 15:f19c023bda04 main-dev

Updated the Controller stub
author Luka Sitas <sitas.luka.97@gmail.com>
date Wed, 26 Feb 2025 19:08:36 -0500
parents 3426c7e91c24
children f0b0d014e448
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
13 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
14 public function index()
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
15 {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
16 $data = [];
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
17
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
18 $data['items'] = {{ model }}::all();
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
19
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
20 return view('{{ tableName }}.index', $data);
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
21 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
22
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 * Show the form for creating a new resource.
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 public function create()
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
27 {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
28 $data = [];
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
29
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
30 return view('{{ tableName }}.create_edit', $data);
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
31 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
32
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
33 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
34 * Store a newly created resource in storage.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
35 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
36 public function store({{ storeRequest }} $request)
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
37 {
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 3
diff changeset
38 $validated = $request->validated();
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 3
diff changeset
39
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
40 //
15
f19c023bda04 Updated the Controller stub
Luka Sitas <sitas.luka.97@gmail.com>
parents: 11
diff changeset
41 ${{ modelVariable }} = new {{ model }}($validated);
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
42
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
43 ${{ modelVariable }}->save();
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
44
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
45 return redirect()->route('{{ tableName }}.index');
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
46 }
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 * Display the specified resource.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
50 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
51 public function show({{ model }} ${{ modelVariable }})
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
52 {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
53 $data = [];
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 $data['item'] = ${{ modelVariable }};
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
56
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
57 return view('{{ tableName }}.show', $data);
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
58 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
59
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 * Show the form for editing the specified resource.
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 public function edit({{ model }} ${{ modelVariable }})
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 $data = [];
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
66
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
67 $data['item'] = ${{ modelVariable }};
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
68
15
f19c023bda04 Updated the Controller stub
Luka Sitas <sitas.luka.97@gmail.com>
parents: 11
diff changeset
69 //load data for relationships
f19c023bda04 Updated the Controller stub
Luka Sitas <sitas.luka.97@gmail.com>
parents: 11
diff changeset
70
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
71 return view('{{ tableName }}.create_edit', $data);
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
72 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
73
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
74 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
75 * Update the specified resource in storage.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
76 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
77 public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }})
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
78 {
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 3
diff changeset
79 $validated = $request->validated();
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 3
diff changeset
80
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
81 // Set the variables
11
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
82 ${{ modelVariable }}->map_values($validated);
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 3
diff changeset
83
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
84 ${{ modelVariable }}->save();
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
85
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
86 return redirect()->route('{{ tableName }}.index');
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
87 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
88
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
89 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
90 * Remove the specified resource from storage.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
91 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
92 public function destroy({{ model }} ${{ modelVariable }})
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
93 {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
94 //
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
95 ${{ modelVariable }}->delete();
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
96
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
97 return redirect()->route('{{ tableName }}.index');
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
98 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents:
diff changeset
99 }