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

Revision

Revision 379 | 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
 
332 lars 5
    use App\Http\Requests\StoreBackendUserRequest;
2 lars 6
    use App\Models\BackendUser;
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;
340 lars 12
    use Illuminate\Support\Facades\Hash;
2 lars 13
    use App\Http\Requests\UserUpdateRequest;
14
 
15
    class BackendUserController extends Controller
16
    {
17
        /**
18
         * Display a listing of the resource.
19
         *
20
         */
21
        public function index(): Factory|View|Application
22
        {
23
            //
24
            $bu = BackendUser::orderBy( "rank" )->orderBy( "email" )->get();
25
            return view( 'backend_users', [ "users" => $bu, ] );
26
        }
27
 
28
        /**
29
         * Show the form for creating a new resource.
30
         *
31
         */
32
        public function create(): Factory|View|Application
33
        {
34
            //
35
            return view( 'backend_user' );
36
        }
37
 
38
        /**
39
         * Store a newly created resource in storage.
40
         *
332 lars 41
         * @param StoreBackendUserRequest $request
2 lars 42
         * @return RedirectResponse
43
         */
388 lars 44
        public function store( StoreBackendUserRequest $request ): string
2 lars 45
        {
46
            //
342 lars 47
            $data = $request->validated();
48
            $data["password"] = Hash::make( $data["password"] );
388 lars 49
	    BackendUser::create( $data );
50
	    return "{}";
2 lars 51
        }
52
 
53
        /**
54
         * Display the specified resource.
55
         *
378 lars 56
         * @param BackendUser $backendUser
2 lars 57
         */
378 lars 58
        public function show( BackendUser $backendUser ): void
2 lars 59
        {
379 lars 60
            echo $backendUser->email . " ( " . $backendUser->name . " )";
2 lars 61
        }
62
 
63
        /**
64
         * Show the form for editing the specified resource.
65
         *
332 lars 66
         * @param BackendUser $backendUser
2 lars 67
         * @return Factory|View|Application
68
         */
332 lars 69
        public function edit( BackendUser $backendUser ): Factory|View|Application
2 lars 70
        {
71
            //
332 lars 72
            $ex = explode( "@", $backendUser->email );
73
            $backendUser->userPart = $ex[0];
74
            return view( 'backend_user', [ "user" => $backendUser, ] );
2 lars 75
        }
76
 
77
 
78
        /**
79
         * Update the specified resource in storage.
80
         *
81
         * @param UserUpdateRequest $request
332 lars 82
         * @param BackendUser $backendUser
2 lars 83
         * @return RedirectResponse
84
         */
388 lars 85
        public function update( UserUpdateRequest $request, BackendUser $backendUser ): String
2 lars 86
        {
87
            //
88
            $data = $request->validated();
341 lars 89
            if ( isset( $data["password"] ) && $data["password"] )
90
            {
91
                $data["password"] = Hash::make( $data["password"] );
92
            }
2 lars 93
            $data["employee"] = intval( $data["employee"] );
94
            $data["terminpflege"] = intval( $data["terminpflege"] );
95
            if ( isset( $data["app_user"] ) )
96
            {
97
                $data["app_user"] = intval( $data["app_user"] );
98
            }
99
            $data["save_session"] = intval( $data["save_session"] );
332 lars 100
            $backendUser->update( $data );
388 lars 101
	    return "{}";
2 lars 102
        }
103
 
104
        /**
105
         * Remove the specified resource from storage.
106
         *
332 lars 107
         * @param BackendUser $backendUser
2 lars 108
         * @return RedirectResponse
109
         */
388 lars 110
        public function destroy( BackendUser $backendUser ): string
2 lars 111
        {
112
            //
332 lars 113
            $backendUser->delete();
388 lars 114
            return "{}";
2 lars 115
        }
116
    }