diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 4685683..8ffc7fc 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers; use App\Models\User; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Str; class UserController extends Controller { @@ -22,7 +24,7 @@ class UserController extends Controller public function show($userId) { - $user = NULL; // 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')); } @@ -31,7 +33,10 @@ class UserController extends Controller { // TASK: find a user by $name and $email // if not found, create a user with $name, $email and random password - $user = NULL; + $user = User::firstOrCreate( + ['name' => $name, 'email' => $email], + ['password' => Hash::make(Str::random(12))] + ); return view('users.show', compact('user')); } @@ -64,5 +69,4 @@ class UserController extends Controller return view('users.index', compact('users')); } - }