Subversion-Projekte lars-tiefland.webanos.marine-sales.de

Revision

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

Revision Autor Zeilennr. Zeile
2 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();
23
            return view( 'backend_users', [ "users" => $bu, ] );
24
        }
25
 
26
        /**
27
         * Show the form for creating a new resource.
28
         *
29
         */
30
        public function create(): Factory|View|Application
31
        {
32
            //
33
            return view( 'backend_user' );
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() );
52
            return redirect( "/backend_users" );
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];
77
            return view( 'backend_user', [ "user" => $bu, ] );
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
            $bu = BackendUser::find( $id );
92
            $data = $request->validated();
93
            if ( is_null( $data["phone"] ) )
94
            {
95
                $data["phone"] = "";
96
            }
97
            if ( is_null( $data["fax"] ) )
98
            {
99
                $data["fax"] = "";
100
            }
101
            if ( is_null( $data["description"] ) )
102
            {
103
                $data["description"] = "";
104
            }
105
            $data["employee"] = intval( $data["employee"] );
106
            $data["terminpflege"] = intval( $data["terminpflege"] );
107
            if ( isset( $data["app_user"] ) )
108
            {
109
                $data["app_user"] = intval( $data["app_user"] );
110
            }
111
            $data["save_session"] = intval( $data["save_session"] );
112
            $bu->update( $data );
113
            return redirect( "/backend_users" );
114
        }
115
 
116
        /**
117
         * Remove the specified resource from storage.
118
         *
119
         * @param int $id
120
         * @return RedirectResponse
121
         */
122
        public function destroy( int $id ): RedirectResponse
123
        {
124
            //
125
            $bu = BackendUser::find( $id );
126
            $bu->delete();
127
            return redirect( "/backend_users" );
128
        }
129
    }