Testing resources
Authenticating as a user
Ensure that you are authenticated to access the app in your TestCase:
use App\Models\User;
protected function setUp(): void
{
parent::setUp();
$this->actingAs(User::factory()->create());
}
Alternatively, if you are using Pest you can use a beforeEach() function at the top of your test file to authenticate:
use App\Models\User;
beforeEach(function () {
$user = User::factory()->create();
actingAs($user);
});