Task 10 - scopes

This commit is contained in:
PovilasKorop
2021-11-16 10:52:52 +02:00
parent 328e51c4ee
commit cdd8ae6be8
4 changed files with 27 additions and 0 deletions
+8
View File
@@ -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()`.
---
+10
View File
@@ -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'));
}
}
+1
View File
@@ -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']);
+8
View File
@@ -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);
}
}