Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sahar_mkr's avatar

sahar_mkr started a new conversation+100 XP

5mos ago

Testing

I want to test this api, here I can create a user but when I get to the controller it shows user is null, why this happens? this api works properly and is so simple but on the test the user created successfully but in controller it is null and makes test fail:

public function index(User $user)
{
    return success('User data', (new UserResource($user));    
}

this is my route:

Route::get('/user/{user}', [UserController::class, 'index']);

this is my test:

public function test_show_user_meta()
{
    $this->withoutMiddleware();
    $user= User::factory()->create();
   
    $response = $this->get('api/user/' . $user->id);
    dd($response);
}