Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1334 | Revision 1486 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

namespace App\Http\Controllers;

use App\Http\Requests\ActionRequest;
use App\Models\Action;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class ActionController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     */
    public function index(): Factory|View|Application
    {
        //
        $actions = Action::orderBy( "rank" )->get();
        return view( 'admin/actions', [ "aktionen" => $actions, ] );
    }

    /**
     * Show the form for creating a new resource.
     *
     */
    public function create(): Factory|View|Application
    {
        //
        return view( 'admin/action' );
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param Request $request
     * @return RedirectResponse
     */
    public function store( Request $request ): RedirectResponse
    {
        //
        $rules = [
            'name'   => 'bail|max:255',
        ];
        $request->validate( $rules );
        $bu = new Action();
        $bu->update( $request->validated() );
        return redirect( "/backend/actions" );
    }

    /**
     * Display the specified resource.
     *
     * @param int $id
     */
    public function show( int $id )
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param int $id
     * @return Factory|View|Application
     */
    public function edit( int $id ): Factory|View|Application
    {
        //
        $action = Action::find( $id );
        return view( 'admin/action', [ "action" => $action, ] );
    }


    /**
     * Update the specified resource in storage.
     *
     * @param ActionRequest $request
     * @param int $id
     * @return RedirectResponse
     */
    public function update( ActionRequest $request, int $id ): RedirectResponse
    {
        //
        $rules = [
            'name'   => 'bail|max:255',
        ];
        $request->validate( $rules );
        $bu = Action::find( $id );
        $data = $request->validated();
        $bu->update( $data );
        return redirect( "/backend/actions" );
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param int $id
     * @return RedirectResponse
     */
    public function destroy( int $id ): RedirectResponse
    {
        //
        $bu = Action::find( $id );
        $bu->delete();
        return redirect( "/backend/actions" );
    }
}