mirror of
https://github.com/10h30/Test-Laravel-Eloquent-Basics.git
synced 2026-06-05 15:07:45 +09:00
Task 10 - scopes
This commit is contained in:
@@ -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()`.
|
||||
|
||||
---
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user