<?php

namespace {{ namespace }};

use {{ namespacedModel }};
use {{ rootNamespace }}Http\Controllers\Controller;
{{ requestUses }}

class {{ class }} extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\View\View
     */
    public function index()
    {
        $data = [];
        $data['items'] = {{ model }}::all();

        return view('{{ tableName }}.index', $data);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\View\View
     */
    public function create()
    {
        $data = [];

        return view('{{ tableName }}.create_edit', $data);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param {{ storeRequest }} $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function store({{ storeRequest }} $request)
    {
        $validated = $request->validated();

        ${{ modelVariable }} = new {{ model }}($validated);
        ${{ modelVariable }}->save();

        return redirect()->route('{{ tableName }}.index');
    }

    /**
     * Display the specified resource.
     *
     * @param {{ model }} ${{ modelVariable }}
     * @return \Illuminate\View\View
     */
    public function show({{ model }} ${{ modelVariable }})
    {
        $data = [];
        $data['item'] = ${{ modelVariable }};

        return view('{{ tableName }}.show', $data);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param {{ model }} ${{ modelVariable }}
     * @return \Illuminate\View\View
     */
    public function edit({{ model }} ${{ modelVariable }})
    {
        $data = [];
        $data['item'] = ${{ modelVariable }};

        // Load data for relationships

        return view('{{ tableName }}.create_edit', $data);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param {{ updateRequest }} $request
     * @param {{ model }} ${{ modelVariable }}
     * @return \Illuminate\Http\RedirectResponse
     */
    public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }})
    {
        $validated = $request->validated();

        ${{ modelVariable }}->map_values($validated);
        ${{ modelVariable }}->save();

        return redirect()->route('{{ tableName }}.index');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param {{ model }} ${{ modelVariable }}
     * @return \Illuminate\Http\RedirectResponse
     */
    public function destroy({{ model }} ${{ modelVariable }})
    {
        ${{ modelVariable }}->delete();

        return redirect()->route('{{ tableName }}.index');
    }
}
