sahar_mkr's avatar

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);
}
1 like
3 replies
Snapey's avatar

Isn't route model binding performed in middleware?

2 likes
vincent15000's avatar

Oh I just noticed the OP has added $this->withoutMiddleware(); in the test.

Please or to participate in this conversation.