Mercurial > packages > magicforger
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/Controller/stubs/controller.stub Tue Jun 27 15:32:47 2023 -0400 @@ -0,0 +1,93 @@ +<?php + +namespace {{ namespace }}; + +use {{ namespacedModel }}; +use {{ rootNamespace }}Http\Controllers\Controller; +{{ requestUses }} + +class {{ class }} extends Controller +{ + /** + * Display a listing of the resource. + */ + public function index() + { + $data = []; + + $data['items'] = {{ model }}::all(); + + return view('{{ tableName }}.index', $data); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + $data = []; + + return view('{{ tableName }}.create_edit', $data); + } + + /** + * Store a newly created resource in storage. + */ + public function store({{ storeRequest }} $request) + { + // + ${{ modelVariable }} = new {{ model }}(); + + //insert the values into the model + + ${{ modelVariable }}->save(); + + return redirect()->route('{{ tableName }}.index'); + } + + /** + * Display the specified resource. + */ + public function show({{ model }} ${{ modelVariable }}) + { + $data = []; + + $data['item'] = ${{ modelVariable }}; + + return view('{{ tableName }}.show', $data); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit({{ model }} ${{ modelVariable }}) + { + $data = []; + + $data['item'] = ${{ modelVariable }}; + + return view('{{ tableName }}.create_edit', $data); + } + + /** + * Update the specified resource in storage. + */ + public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }}) + { + // Set the variables + ${{ modelVariable }}->save(); + + return redirect()->route('{{ tableName }}.index'); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy({{ model }} ${{ modelVariable }}) + { + // + ${{ modelVariable }}->delete(); + + return redirect()->route('{{ tableName }}.index'); + } +}
