Skip to content

Commit

Permalink
T7 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 16819c5 commit e6993ec
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,33 @@ public function check_create($name, $email)
{
// TASK: find a user by $name and $email
// if not found, create a user with $name, $email and random password
$user = User::where('name', $name)->where('email', $email)->first(); // updated or created user
$user = User::where('name', $name)->where('email', $email)->first();
if (!$user) {
$user = User::create([
'name' => $name,
'email' => $email,
'password' => bcrypt(str_random(8))
]);

$user = User::create([
'name' => $name,
'email' => $email,
'password' => bcrypt(str_random(8))
]);
}
return view('users.show', compact('user'));
}

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 = User::where('name', $name)->first();
if ($user) {
$user->email = $email;
$user->save();
}
else {
$user = User::create([
'name' => $name,
'email' => $email,
'password' => bcrypt(str_random(8))
]);
}
return view('users.show', compact('user'));
}

Expand Down

0 comments on commit e6993ec

Please sign in to comment.