mirror of
https://github.com/10h30/Test-Laravel-Eloquent-Basics.git
synced 2026-07-11 10:55:52 +09:00
Complete Task 4
This commit is contained in:
@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
@@ -22,7 +24,7 @@ class UserController extends Controller
|
|||||||
|
|
||||||
public function show($userId)
|
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'));
|
return view('users.show', compact('user'));
|
||||||
}
|
}
|
||||||
@@ -31,7 +33,10 @@ class UserController extends Controller
|
|||||||
{
|
{
|
||||||
// TASK: find a user by $name and $email
|
// TASK: find a user by $name and $email
|
||||||
// if not found, create a user with $name, $email and random password
|
// 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'));
|
return view('users.show', compact('user'));
|
||||||
}
|
}
|
||||||
@@ -64,5 +69,4 @@ class UserController extends Controller
|
|||||||
|
|
||||||
return view('users.index', compact('users'));
|
return view('users.index', compact('users'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user