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

Revision

Revision 2 | Revision 324 | 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
            //
323 lars 91
            $request->validated();
2 lars 92
            $bu = BackendUser::find( $id );
93
            $data = $request->validated();
94
            if ( is_null( $data["phone"] ) )
95
            {
96
                $data["phone"] = "";
97
            }
98
            if ( is_null( $data["fax"] ) )
99
            {
100
                $data["fax"] = "";
101
            }
102
            if ( is_null( $data["description"] ) )
103
            {
104
                $data["description"] = "";
105
            }
106
            $data["employee"] = intval( $data["employee"] );
107
            $data["terminpflege"] = intval( $data["terminpflege"] );
108
            if ( isset( $data["app_user"] ) )
109
            {
110
                $data["app_user"] = intval( $data["app_user"] );
111
            }
112
            $data["save_session"] = intval( $data["save_session"] );
113
            $bu->update( $data );
114
            return redirect( "/backend_users" );
115
        }
116
 
117
        /**
118
         * Remove the specified resource from storage.
119
         *
120
         * @param int $id
121
         * @return RedirectResponse
122
         */
123
        public function destroy( int $id ): RedirectResponse
124
        {
125
            //
126
            $bu = BackendUser::find( $id );
127
            $bu->delete();
128
            return redirect( "/backend_users" );
129
        }
130
    }