diff --git a/README.md b/README.md index edc9544..473ef00 100644 --- a/README.md +++ b/README.md @@ -104,3 +104,11 @@ In `app/Http/Controllers/ProjectController.php` file method `destroy()`, change Test method `test_soft_delete_projects()`. --- + +## Task 10. Scopes with Filters. + +In `app/Http/Controllers/UserController.php` file method `only_active()`, make the main statement work and to filter records where email_verified_at is not null. + +Test method `test_active_users()`. + +--- diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index a62b932..9b8c73d 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -55,4 +55,14 @@ class UserController extends Controller return redirect('/')->with('success', 'Users deleted'); } + + public function only_active() + { + // TASK: That "active()" doesn't exist at the moment. + // Create this scope to filter "where email_verified_at is not null" + $users = User::active()->get(); + + return view('users.index', compact('users')); + } + } diff --git a/routes/web.php b/routes/web.php index 7359f9b..8a5b429 100644 --- a/routes/web.php +++ b/routes/web.php @@ -23,6 +23,7 @@ Route::get('/', function () { // Some routes are just for the purpose of replicating some testing scenario Route::get('users', [UserController::class, 'index']); +Route::get('users/active', [UserController::class, 'only_active']); Route::get('users/{userId}', [UserController::class, 'show']); Route::get('users/check/{name}/{email}', [UserController::class, 'check_create']); Route::get('users/check_update/{name}/{email}', [UserController::class, 'check_update']); diff --git a/tests/Feature/EloquentTest.php b/tests/Feature/EloquentTest.php index 2200bd6..96ea436 100644 --- a/tests/Feature/EloquentTest.php +++ b/tests/Feature/EloquentTest.php @@ -128,4 +128,12 @@ class EloquentTest extends TestCase $response = $this->delete('projects/' . $project->id); $response->assertSee('Some name'); } + + public function test_active_users() + { + $user = User::factory()->create(['email_verified_at' => NULL]); + + $response = $this->get('users/active'); + $response->assertDontSee($user->name); + } }