Mercurial > packages > magicforger
comparison src/Generator/Controller/stubs/controller.stub @ 34:f65ab84ee47f default
merge with codex
| author | luka |
|---|---|
| date | Wed, 10 Sep 2025 21:00:47 -0400 |
| parents | 45f384a24553 |
| children |
comparison
equal
deleted
inserted
replaced
| 10:a9ff874afdbd | 34:f65ab84ee47f |
|---|---|
| 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 * @param {{ filterRequest }} $request | |
| 15 * @return \Illuminate\View\View | |
| 13 */ | 16 */ |
| 14 public function index() | 17 public function index({{ filterRequest }} $request) |
| 15 { | 18 { |
| 16 $data = []; | 19 $validated = $request->validated(); |
| 17 | 20 $data = []; |
| 18 $data['items'] = {{ model }}::all(); | 21 $data['items'] = {{ model }}::get_data($validated); |
| 22 $data = array_merge($data, {{ model }}::load_index()); | |
| 19 | 23 |
| 20 return view('{{ tableName }}.index', $data); | 24 return view('{{ tableName }}.index', $data); |
| 21 } | 25 } |
| 22 | 26 |
| 27 public function get_data() | |
| 28 { | |
| 29 $data = []; | |
| 30 $data['records'] = {{ model }}::get_data([]); | |
| 31 $data['total_records'] = count($data['records']); | |
| 32 | |
| 33 return $data; | |
| 34 } | |
| 35 | |
| 23 /** | 36 /** |
| 24 * Show the form for creating a new resource. | 37 * Show the form for creating a new resource. |
| 38 * | |
| 39 * @return \Illuminate\View\View | |
| 25 */ | 40 */ |
| 26 public function create() | 41 public function create() |
| 27 { | 42 { |
| 28 $data = []; | 43 $data = []; |
| 44 $data = array_merge($data, {{ model }}::load_create()); | |
| 29 | 45 |
| 30 return view('{{ tableName }}.create_edit', $data); | 46 return view('{{ tableName }}.create_edit', $data); |
| 31 } | 47 } |
| 32 | 48 |
| 33 /** | 49 /** |
| 34 * Store a newly created resource in storage. | 50 * Store a newly created resource in storage. |
| 51 * | |
| 52 * @param {{ storeRequest }} $request | |
| 53 * @return \Illuminate\Http\RedirectResponse | |
| 35 */ | 54 */ |
| 36 public function store({{ storeRequest }} $request) | 55 public function store({{ storeRequest }} $request) |
| 37 { | 56 { |
| 38 $validated = $request->validated(); | 57 $validated = $request->validated(); |
| 39 | 58 |
| 40 // | 59 {{ model }}::create($validated); |
| 41 ${{ modelVariable }} = new {{ model }}(); | |
| 42 | |
| 43 //insert the values into the model | |
| 44 // {{ valuesForCreation }} | |
| 45 | |
| 46 ${{ modelVariable }}->save(); | |
| 47 | 60 |
| 48 return redirect()->route('{{ tableName }}.index'); | 61 return redirect()->route('{{ tableName }}.index'); |
| 49 } | 62 } |
| 50 | 63 |
| 51 /** | 64 /** |
| 52 * Display the specified resource. | 65 * Display the specified resource. |
| 66 * | |
| 67 * @param {{ model }} ${{ modelVariable }} | |
| 68 * @return \Illuminate\View\View | |
| 53 */ | 69 */ |
| 54 public function show({{ model }} ${{ modelVariable }}) | 70 public function show({{ model }} ${{ modelVariable }}) |
| 55 { | 71 { |
| 56 $data = []; | 72 $data = []; |
| 57 | 73 $data['item'] = ${{ modelVariable }}; |
| 58 $data['item'] = ${{ modelVariable }}; | 74 $data['fields'] = (new {{ model }}())->getFillable(); |
| 59 | 75 |
| 60 return view('{{ tableName }}.show', $data); | 76 return view('{{ tableName }}.show', $data); |
| 77 } | |
| 78 | |
| 79 /** | |
| 80 * Returns the resource in JSON format. | |
| 81 * | |
| 82 * @param ModelType $modelVariable | |
| 83 * @return string | |
| 84 */ | |
| 85 public function load({{ model }} ${{ modelVariable }}) | |
| 86 { | |
| 87 return ${{ modelVariable }}->toJson(); | |
| 61 } | 88 } |
| 62 | 89 |
| 63 /** | 90 /** |
| 64 * Show the form for editing the specified resource. | 91 * Show the form for editing the specified resource. |
| 92 * | |
| 93 * @param {{ model }} ${{ modelVariable }} | |
| 94 * @return \Illuminate\View\View | |
| 65 */ | 95 */ |
| 66 public function edit({{ model }} ${{ modelVariable }}) | 96 public function edit({{ model }} ${{ modelVariable }}) |
| 67 { | 97 { |
| 68 $data = []; | 98 $data = []; |
| 99 $data['item'] = ${{ modelVariable }}; | |
| 69 | 100 |
| 70 $data['item'] = ${{ modelVariable }}; | 101 // Load data for relationships |
| 102 $data = array_merge($data, {{ model }}::load_edit()); | |
| 71 | 103 |
| 72 return view('{{ tableName }}.create_edit', $data); | 104 return view('{{ tableName }}.create_edit', $data); |
| 73 } | 105 } |
| 74 | 106 |
| 75 /** | 107 /** |
| 76 * Update the specified resource in storage. | 108 * Update the specified resource in storage. |
| 109 * | |
| 110 * @param {{ updateRequest }} $request | |
| 111 * @param {{ model }} ${{ modelVariable }} | |
| 112 * @return \Illuminate\Http\RedirectResponse | |
| 77 */ | 113 */ |
| 78 public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }}) | 114 public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }}) |
| 79 { | 115 { |
| 80 $validated = $request->validated(); | 116 $validated = $request->validated(); |
| 81 | 117 |
| 82 // Set the variables | 118 ${{ modelVariable }}->update($validated); |
| 83 //{{ valuesForCreation }} | |
| 84 | 119 |
| 85 ${{ modelVariable }}->save(); | 120 return redirect()->route('{{ tableName }}.index'); |
| 86 | |
| 87 return redirect()->route('{{ tableName }}.index'); | |
| 88 } | 121 } |
| 89 | 122 |
| 90 /** | 123 /** |
| 91 * Remove the specified resource from storage. | 124 * Remove the specified resource from storage. |
| 125 * | |
| 126 * @param {{ model }} ${{ modelVariable }} | |
| 127 * @return \Illuminate\Http\RedirectResponse | |
| 92 */ | 128 */ |
| 93 public function destroy({{ model }} ${{ modelVariable }}) | 129 public function destroy({{ model }} ${{ modelVariable }}) |
| 94 { | 130 { |
| 95 // | 131 ${{ modelVariable }}->delete(); |
| 96 ${{ modelVariable }}->delete(); | |
| 97 | 132 |
| 98 return redirect()->route('{{ tableName }}.index'); | 133 return redirect()->route('{{ tableName }}.index'); |
| 99 } | 134 } |
| 100 } | 135 } |
