mirror of
https://github.com/10h30/Test-Laravel-Eloquent-Basics.git
synced 2026-07-18 14:14:00 +09:00
Complete all stats
This commit is contained in:
@@ -12,7 +12,7 @@ class ProjectController extends Controller
|
||||
{
|
||||
// TASK: Currently this statement fails. Fix the underlying issue.
|
||||
Project::create([
|
||||
'name' => $request->name
|
||||
'name' => $request->name,
|
||||
]);
|
||||
|
||||
return redirect('/')->with('success', 'Project created');
|
||||
@@ -26,6 +26,9 @@ class ProjectController extends Controller
|
||||
// where name = $request->old_name
|
||||
|
||||
// Insert Eloquent statement below
|
||||
Project::where('name', $request->old_name)
|
||||
->update(['name' => $request->new_name]);
|
||||
|
||||
|
||||
return redirect('/')->with('success', 'Projects updated');
|
||||
}
|
||||
@@ -35,7 +38,7 @@ class ProjectController extends Controller
|
||||
Project::destroy($projectId);
|
||||
|
||||
// TASK: change this Eloquent statement to include the soft-deletes records
|
||||
$projects = Project::all();
|
||||
$projects = Project::withTrashed()->get();
|
||||
|
||||
return view('projects.index', compact('projects'));
|
||||
}
|
||||
|
||||
@@ -45,7 +45,13 @@ class UserController extends Controller
|
||||
{
|
||||
// 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::updateOrCreate(
|
||||
['name' => $name],
|
||||
[
|
||||
'email' => $email,
|
||||
'password' => Hash::make(Str::random(12)),
|
||||
]
|
||||
);
|
||||
|
||||
return view('users.show', compact('user'));
|
||||
}
|
||||
@@ -57,7 +63,7 @@ class UserController extends Controller
|
||||
// $request->users is an array of IDs, ex. [1, 2, 3]
|
||||
|
||||
// Insert Eloquent statement here
|
||||
|
||||
$users = User::whereIn('id', $request->users)->delete();
|
||||
return redirect('/')->with('success', 'Users deleted');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user