Mercurial > packages > magicforger
comparison src/Generator/Controller/stubs/controller.stub @ 3:6468684362c2
It works! Created a controller, no update insert but it works
| author | luka |
|---|---|
| date | Tue, 27 Jun 2023 15:32:47 -0400 |
| parents | |
| children | b0b2e79ad8e6 |
comparison
equal
deleted
inserted
replaced
| 2:cf9993c5c7df | 3:6468684362c2 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace {{ namespace }}; | |
| 4 | |
| 5 use {{ namespacedModel }}; | |
| 6 use {{ rootNamespace }}Http\Controllers\Controller; | |
| 7 {{ requestUses }} | |
| 8 | |
| 9 class {{ class }} extends Controller | |
| 10 { | |
| 11 /** | |
| 12 * Display a listing of the resource. | |
| 13 */ | |
| 14 public function index() | |
| 15 { | |
| 16 $data = []; | |
| 17 | |
| 18 $data['items'] = {{ model }}::all(); | |
| 19 | |
| 20 return view('{{ tableName }}.index', $data); | |
| 21 } | |
| 22 | |
| 23 /** | |
| 24 * Show the form for creating a new resource. | |
| 25 */ | |
| 26 public function create() | |
| 27 { | |
| 28 $data = []; | |
| 29 | |
| 30 return view('{{ tableName }}.create_edit', $data); | |
| 31 } | |
| 32 | |
| 33 /** | |
| 34 * Store a newly created resource in storage. | |
| 35 */ | |
| 36 public function store({{ storeRequest }} $request) | |
| 37 { | |
| 38 // | |
| 39 ${{ modelVariable }} = new {{ model }}(); | |
| 40 | |
| 41 //insert the values into the model | |
| 42 | |
| 43 ${{ modelVariable }}->save(); | |
| 44 | |
| 45 return redirect()->route('{{ tableName }}.index'); | |
| 46 } | |
| 47 | |
| 48 /** | |
| 49 * Display the specified resource. | |
| 50 */ | |
| 51 public function show({{ model }} ${{ modelVariable }}) | |
| 52 { | |
| 53 $data = []; | |
| 54 | |
| 55 $data['item'] = ${{ modelVariable }}; | |
| 56 | |
| 57 return view('{{ tableName }}.show', $data); | |
| 58 } | |
| 59 | |
| 60 /** | |
| 61 * Show the form for editing the specified resource. | |
| 62 */ | |
| 63 public function edit({{ model }} ${{ modelVariable }}) | |
| 64 { | |
| 65 $data = []; | |
| 66 | |
| 67 $data['item'] = ${{ modelVariable }}; | |
| 68 | |
| 69 return view('{{ tableName }}.create_edit', $data); | |
| 70 } | |
| 71 | |
| 72 /** | |
| 73 * Update the specified resource in storage. | |
| 74 */ | |
| 75 public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }}) | |
| 76 { | |
| 77 // Set the variables | |
| 78 ${{ modelVariable }}->save(); | |
| 79 | |
| 80 return redirect()->route('{{ tableName }}.index'); | |
| 81 } | |
| 82 | |
| 83 /** | |
| 84 * Remove the specified resource from storage. | |
| 85 */ | |
| 86 public function destroy({{ model }} ${{ modelVariable }}) | |
| 87 { | |
| 88 // | |
| 89 ${{ modelVariable }}->delete(); | |
| 90 | |
| 91 return redirect()->route('{{ tableName }}.index'); | |
| 92 } | |
| 93 } |
