Skip to content

Commit

Permalink
T4 Update UserController.php
Browse files Browse the repository at this point in the history
  • Loading branch information
imtyaz-17 authored Jul 4, 2024
1 parent 55d29e9 commit 9351425
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function index()

public function show($userId)
{
$user = findOrFail($userId); // TASK: find user by $userId or show "404 not found" page
$user = User::findOrFail($userId); // TASK: find user by $userId or show "404 not found" page

return view('users.show', compact('user'));
}
Expand All @@ -43,8 +43,14 @@ public function check_update($name, $email)
{
// TASK: find a user by $name and update it with $email
// if not found, create a user with $name, $email and random password
$user = NULL; // updated or created user

$user = User::where('name', $name)->where('email', $email)->first(); // updated or created user
if (!$user) {
$user = User::create([
'name' => $name,
'email' => $email,
'password' => bcrypt(str_random(8))
]);
}
return view('users.show', compact('user'));
}

Expand Down

0 comments on commit 9351425

Please sign in to comment.