Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1514 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
108 lars 1
<?php
2
 
1486 lars 3
    namespace App\Http\Controllers;
108 lars 4
 
1486 lars 5
    use App\Http\Requests\ActionRequest;
6
    use App\Models\Action;
7
    use Illuminate\Contracts\Foundation\Application;
8
    use Illuminate\Contracts\View\Factory;
9
    use Illuminate\Contracts\View\View;
10
    use Illuminate\Http\RedirectResponse;
11
    use Illuminate\Http\Request;
108 lars 12
 
1486 lars 13
    class ActionController extends Controller
1334 lars 14
    {
1486 lars 15
        /**
16
         * Display a listing of the resource.
17
         *
18
         */
19
        public function index(): Factory|View|Application
20
        {
21
            //
22
            $actions = Action::orderBy( "rank" )->get();
23
            foreach ( $actions as $aId => $aktion )
24
            {
25
                $gVon = strtotime( $aktion->valid_from );
26
                $gBis = strtotime( $aktion->valid_to );
27
                $jetzt = time();
28
                if ( $jetzt >= $gVon && $jetzt <= $gBis )
29
                {
30
                    $status = 0;
31
                }
32
                elseif ( $jetzt < $gVon )
33
                {
34
                    $status = 1;
35
                }
36
                else
37
                {
38
                    $status = 2;
39
                }
1487 lars 40
                $aktion->status = $status;
1334 lars 41
 
1486 lars 42
            }
43
            return view( 'admin/actions', [ "aktionen" => $actions, ] );
44
        }
1334 lars 45
 
1486 lars 46
        /**
47
         * Show the form for creating a new resource.
48
         *
49
         */
50
        public function create(): Factory|View|Application
51
        {
52
            //
53
            return view( 'admin/action' );
54
        }
1334 lars 55
 
1486 lars 56
        /**
57
         * Store a newly created resource in storage.
58
         *
59
         * @param Request $request
60
         * @return RedirectResponse
61
         */
62
        public function store( Request $request ): RedirectResponse
63
        {
64
            //
65
            $rules = [
66
                'name' => 'bail|max:255',
67
            ];
68
            $request->validate( $rules );
69
            $bu = new Action();
70
            $bu->update( $request->validated() );
71
            return redirect( "/backend/actions" );
72
        }
1334 lars 73
 
1486 lars 74
        /**
75
         * Display the specified resource.
76
         *
77
         * @param int $id
78
         */
79
        public function show( int $id )
80
        {
81
            //
82
        }
1334 lars 83
 
1486 lars 84
        /**
85
         * Show the form for editing the specified resource.
86
         *
87
         * @param int $id
88
         * @return Factory|View|Application
89
         */
90
        public function edit( int $id ): Factory|View|Application
91
        {
92
            //
1514 lars 93
            \View::share( "lType", "k" );
1518 lars 94
            $action = Action::with( 'medium.medium' )->find( $id );
1486 lars 95
            return view( 'admin/action', [ "action" => $action, ] );
96
        }
1334 lars 97
 
98
 
1486 lars 99
        /**
100
         * Update the specified resource in storage.
101
         *
102
         * @param ActionRequest $request
103
         * @param int $id
104
         * @return RedirectResponse
105
         */
106
        public function update( ActionRequest $request, int $id ): RedirectResponse
107
        {
108
            //
109
            $rules = [
110
                'name' => 'bail|max:255',
111
            ];
112
            $request->validate( $rules );
113
            $bu = Action::find( $id );
114
            $data = $request->validated();
115
            $bu->update( $data );
116
            return redirect( "/backend/actions" );
117
        }
118
 
119
        /**
120
         * Remove the specified resource from storage.
121
         *
122
         * @param int $id
123
         * @return RedirectResponse
124
         */
125
        public function destroy( int $id ): RedirectResponse
126
        {
127
            //
128
            $bu = Action::find( $id );
129
            $bu->delete();
130
            return redirect( "/backend/actions" );
131
        }
1334 lars 132
    }