comparison src/Generator/Controller/stubs/controller.stub @ 21:f0b0d014e448 main-dev

Cleaning up code based on AI overlord review
author Luka Sitas <sitas.luka.97@gmail.com>
date Wed, 26 Feb 2025 19:45:08 -0500
parents f19c023bda04
children 827efbf4d73c
comparison
equal deleted inserted replaced
20:81a76472ba21 21:f0b0d014e448
8 8
9 class {{ class }} extends Controller 9 class {{ class }} extends Controller
10 { 10 {
11 /** 11 /**
12 * Display a listing of the resource. 12 * Display a listing of the resource.
13 *
14 * @return \Illuminate\View\View
13 */ 15 */
14 public function index() 16 public function index()
15 { 17 {
16 $data = []; 18 $data = [];
17 19 $data['items'] = {{ model }}::all();
18 $data['items'] = {{ model }}::all();
19 20
20 return view('{{ tableName }}.index', $data); 21 return view('{{ tableName }}.index', $data);
21 } 22 }
22 23
23 /** 24 /**
24 * Show the form for creating a new resource. 25 * Show the form for creating a new resource.
26 *
27 * @return \Illuminate\View\View
25 */ 28 */
26 public function create() 29 public function create()
27 { 30 {
28 $data = []; 31 $data = [];
29 32
30 return view('{{ tableName }}.create_edit', $data); 33 return view('{{ tableName }}.create_edit', $data);
31 } 34 }
32 35
33 /** 36 /**
34 * Store a newly created resource in storage. 37 * Store a newly created resource in storage.
38 *
39 * @param {{ storeRequest }} $request
40 * @return \Illuminate\Http\RedirectResponse
35 */ 41 */
36 public function store({{ storeRequest }} $request) 42 public function store({{ storeRequest }} $request)
37 { 43 {
38 $validated = $request->validated(); 44 $validated = $request->validated();
39 45
40 // 46 ${{ modelVariable }} = new {{ model }}($validated);
41 ${{ modelVariable }} = new {{ model }}($validated); 47 ${{ modelVariable }}->save();
42
43 ${{ modelVariable }}->save();
44 48
45 return redirect()->route('{{ tableName }}.index'); 49 return redirect()->route('{{ tableName }}.index');
46 } 50 }
47 51
48 /** 52 /**
49 * Display the specified resource. 53 * Display the specified resource.
54 *
55 * @param {{ model }} ${{ modelVariable }}
56 * @return \Illuminate\View\View
50 */ 57 */
51 public function show({{ model }} ${{ modelVariable }}) 58 public function show({{ model }} ${{ modelVariable }})
52 { 59 {
53 $data = []; 60 $data = [];
54 61 $data['item'] = ${{ modelVariable }};
55 $data['item'] = ${{ modelVariable }};
56 62
57 return view('{{ tableName }}.show', $data); 63 return view('{{ tableName }}.show', $data);
58 } 64 }
59 65
60 /** 66 /**
61 * Show the form for editing the specified resource. 67 * Show the form for editing the specified resource.
68 *
69 * @param {{ model }} ${{ modelVariable }}
70 * @return \Illuminate\View\View
62 */ 71 */
63 public function edit({{ model }} ${{ modelVariable }}) 72 public function edit({{ model }} ${{ modelVariable }})
64 { 73 {
65 $data = []; 74 $data = [];
75 $data['item'] = ${{ modelVariable }};
66 76
67 $data['item'] = ${{ modelVariable }}; 77 // Load data for relationships
68 78
69 //load data for relationships 79 return view('{{ tableName }}.create_edit', $data);
70
71 return view('{{ tableName }}.create_edit', $data);
72 } 80 }
73 81
74 /** 82 /**
75 * Update the specified resource in storage. 83 * Update the specified resource in storage.
84 *
85 * @param {{ updateRequest }} $request
86 * @param {{ model }} ${{ modelVariable }}
87 * @return \Illuminate\Http\RedirectResponse
76 */ 88 */
77 public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }}) 89 public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }})
78 { 90 {
79 $validated = $request->validated(); 91 $validated = $request->validated();
80 92
81 // Set the variables
82 ${{ modelVariable }}->map_values($validated); 93 ${{ modelVariable }}->map_values($validated);
94 ${{ modelVariable }}->save();
83 95
84 ${{ modelVariable }}->save(); 96 return redirect()->route('{{ tableName }}.index');
85
86 return redirect()->route('{{ tableName }}.index');
87 } 97 }
88 98
89 /** 99 /**
90 * Remove the specified resource from storage. 100 * Remove the specified resource from storage.
101 *
102 * @param {{ model }} ${{ modelVariable }}
103 * @return \Illuminate\Http\RedirectResponse
91 */ 104 */
92 public function destroy({{ model }} ${{ modelVariable }}) 105 public function destroy({{ model }} ${{ modelVariable }})
93 { 106 {
94 // 107 ${{ modelVariable }}->delete();
95 ${{ modelVariable }}->delete();
96 108
97 return redirect()->route('{{ tableName }}.index'); 109 return redirect()->route('{{ tableName }}.index');
98 } 110 }
99 } 111 }