UserSettingsController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 2
b 0
f 0
dl 0
loc 75
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 10 1
A index() 0 5 1
A store() 0 10 2
1
<?php
2
3
namespace App\Http\Controllers\User;
4
5
use Inertia\Inertia;
6
use Illuminate\Http\Request;
7
use Illuminate\Support\Facades\Log;
8
9
use App\Models\User;
10
use App\Models\UserSetting;
11
12
use App\Traits\UserSettingsTrait;
13
14
use App\Http\Controllers\Controller;
15
use App\Http\Requests\User\UpdateUserRequest;
16
use App\Http\Requests\User\UserNotificationsRequest;
17
18
class UserSettingsController extends Controller
19
{
20
    use UserSettingsTrait;
21
22
    /**
23
     *  Show the User Settings Page
24
     */
25
    public function index(Request $request)
26
    {
27
        return Inertia::render('User/Settings', [
28
            'user'     => $request->user()->makeVisible('user_id'),
29
            'settings' => $this->filterUserSettings($request->user()),
30
        ]);
31
    }
32
33
    /**
34
     * Show the form for creating a new resource.
35
     *
36
     * @return \Illuminate\Http\Response
37
     */
38
    // public function create()
39
    // {
40
    //     //
41
    // }
42
43
    /**
44
     *  Submit the User Notification settings
45
     */
46
    public function store(UserNotificationsRequest $request)
47
    {
48
        foreach($request->settingsData as $setting)
49
        {
50
            UserSetting::where('user_id', $request->user_id)->where('setting_type_id', $setting['setting_type_id'])->update([
51
                'value' => $setting['value'],
52
            ]);
53
        }
54
55
        return back()->with(['message' => 'Settings Updated', 'type' => 'success']);
56
    }
57
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param  int  $id
62
     * @return \Illuminate\Http\Response
63
     */
64
    // public function show($id)
65
    // {
66
    //     //
67
    // }
68
69
    /**
70
     * Show the form for editing the specified resource.
71
     *
72
     * @param  int  $id
73
     * @return \Illuminate\Http\Response
74
     */
75
    // public function edit($id)
76
    // {
77
    //     //
78
    // }
79
80
    /**
81
     *  update a users account settings
82
     */
83
    public function update(UpdateUserRequest $request, $id)
84
    {
85
        $user = User::findOrFail($id);
86
        $user->update($request->toArray());
87
88
        Log::stack(['auth', 'user'])->info('User information for User '.$user->username.' (User ID - '.$user->user_id.')has been update by '.$request->user()->username);
89
90
        return back()->with([
91
            'message' => 'Account Details Updated',
92
            'type'    => 'success',
93
        ]);
94
    }
95
96
    /**
97
     * Remove the specified resource from storage.
98
     *
99
     * @param  int  $id
100
     * @return \Illuminate\Http\Response
101
     */
102
    // public function destroy($id)
103
    // {
104
    //     //
105
    // }
106
}
107