-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathUserController.php
More file actions
48 lines (40 loc) · 1.4 KB
/
Copy pathUserController.php
File metadata and controls
48 lines (40 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use Illuminate\Support\Facades\Auth;
use App\Tags;
class UserController extends Controller
{
public function index()
{
$user = User::where('id', Auth::user()->id)->firstOrFail();
$tag = Tags::where('user_id', Auth::user()->id)->first();
return view('sLogs.profile', compact('user', 'tag'));
}
public function edit(Request $request)
{
$user = User::where('id', Auth::user()->id)->firstOrFail();
$tags = $user->tags;
$user->name = $request->name;
$user->email = $request->email;
foreach($tags as $tag) {
$tag->tag = $request->tag;
$tag->streak = $request->streak;
$tag->save();
}
$user->save();
return redirect()->back()->with("status", "Profile updated successfully!");
}
public function password(Request $request)
{
if ($request->input('password_new') == $request->input('password_confirmation')) {
$user = User::where('id', Auth::user()->id)->first();
$user->password = bcrypt($request->password_new);
$user->save();
return redirect()->back()->with("status", "Password updated successfully!");
} else {
return redirect()->back()->with("error", "Sorry! your passwords don't match");
}
}
}