Subversion-Projekte lars-tiefland.webanos.faltradxxs.de

Revision

Revision 27 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
24 lars 1
<?php
2
 
3
    namespace App\Http\Controllers;
4
 
5
    use App\Models\BackendUser;
6
    use Illuminate\Contracts\Foundation\Application;
7
    use Illuminate\Contracts\View\Factory;
8
    use Illuminate\Contracts\View\View;
9
    use Illuminate\Http\RedirectResponse;
10
    use Illuminate\Http\Request;
11
    use App\Http\Requests\UserUpdateRequest;
12
 
13
    class BackendUserController extends Controller
14
    {
15
        /**
16
         * Display a listing of the resource.
17
         *
18
         */
19
        public function index(): Factory|View|Application
20
        {
21
            //
22
            $bu = BackendUser::orderBy( "rank" )->orderBy( "email" )->get();
26 lars 23
            return view( 'backend_users', [ "users" => $bu, ] );
24 lars 24
        }
25
 
26
        /**
27
         * Show the form for creating a new resource.
28
         *
29
         */
30
        public function create(): Factory|View|Application
31
        {
32
            //
26 lars 33
            return view( 'backend_user' );
24 lars 34
        }
35
 
36
        /**
37
         * Store a newly created resource in storage.
38
         *
39
         * @param Request $request
40
         * @return RedirectResponse
41
         */
42
        public function store( Request $request ): RedirectResponse
43
        {
44
            //
45
            $rules = [
46
                'name'   => 'bail|max:255',
47
                'passwd' => 'bail|min:8|required|confirmed'
48
            ];
49
            $request->validate( $rules );
50
            $bu = new BackendUser();
51
            $bu->update( $request->validated() );
28 lars 52
            return redirect( "/backend_users" );
24 lars 53
        }
54
 
55
        /**
56
         * Display the specified resource.
57
         *
58
         * @param int $id
59
         */
60
        public function show( int $id )
61
        {
62
            //
63
        }
64
 
65
        /**
66
         * Show the form for editing the specified resource.
67
         *
68
         * @param int $id
69
         * @return Factory|View|Application
70
         */
71
        public function edit( int $id ): Factory|View|Application
72
        {
73
            //
74
            $bu = BackendUser::find( $id );
75
            $ex = explode( "@", $bu->email );
76
            $bu->userPart = $ex[0];
26 lars 77
            return view( 'backend_user', [ "user" => $bu, ] );
24 lars 78
        }
79
 
80
 
81
        /**
82
         * Update the specified resource in storage.
83
         *
84
         * @param UserUpdateRequest $request
85
         * @param int $id
86
         * @return RedirectResponse
87
         */
88
        public function update( UserUpdateRequest $request, int $id ): RedirectResponse
89
        {
90
            //
91
            $rules = [
92
                'name'   => 'bail|max:255',
93
                'passwd' => 'bail|sometimes|confirmed'
94
            ];
95
            $request->validate( $rules );
96
            $bu = BackendUser::find( $id );
97
            $data = $request->validated();
98
            if ( is_null( $data["phone"] ) )
99
            {
100
                $data["phone"] = "";
101
            }
102
            if ( is_null( $data["fax"] ) )
103
            {
104
                $data["fax"] = "";
105
            }
106
            if ( is_null( $data["description"] ) )
107
            {
108
                $data["description"] = "";
109
            }
110
            $data["employee"] = intval( $data["employee"] );
111
            $data["terminpflege"] = intval( $data["terminpflege"] );
112
            if ( isset( $data["app_user"] ) )
113
            {
114
                $data["app_user"] = intval( $data["app_user"] );
115
            }
116
            $data["save_session"] = intval( $data["save_session"] );
117
            $bu->update( $data );
28 lars 118
            return redirect( "/backend_users" );
24 lars 119
        }
120
 
121
        /**
122
         * Remove the specified resource from storage.
123
         *
124
         * @param int $id
125
         * @return RedirectResponse
126
         */
127
        public function destroy( int $id ): RedirectResponse
128
        {
129
            //
130
            $bu = BackendUser::find( $id );
131
            $bu->delete();
28 lars 132
            return redirect( "/backend_users" );
24 lars 133
        }
134
    }