ProfileController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A update() 0 14 3
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\UpdateProfile;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Hash;
8
use Illuminate\Support\Facades\Log;
9
10
class ProfileController extends Controller
11
{
12
    public function get()
13
    {
14
        return view('profile');
15
    }
16
17
    public function update(UpdateProfile $request)
18
    {
19
        $validated = $request->validated();
20
        $user = Auth::user();
21
        if ($validated['name']) {
22
            $user->name = $validated['name'];
23
            Log::info('User#' . $user->id . ' changed its name to ' . $validated['name']);
24
        }
25
        if ($validated['password']) {
26
            $user->password = Hash::make($validated['password']);
27
            Log::info('User#' . $user->id . ' changed its password');
28
        }
29
        $user->save();
30
        return redirect()->route('profile.show')->with('status', 'Updated profile successfully!');
31
    }
32
}
33