Laravel 5.7. I have a test like this:
/** @test */
public function do_nothing_test()
{
$user = factory(User::class)->states('app')->make();
$this->actingAs($user, 'api');
$response = $this->postJson('some_endpoint', ['foobar' => 3]);
$this->assertEquals(1, Foobar::count());
}
which calls an endpoint in a controller that tries to get the logged in user:
public function update_foobar($request)
{
$userId = auth()->user()->id;
Foobar::create(['userId' => $userId, 'foobar' => $request->foobar]);
}
The value of $id
is null
. How can I get the test to work so that the user's details are available to the controller?