Lars-Janssen's avatar

Laravel test

Hi,

I've a test that looks like this:

$user = factory(User::class)->create([
    'email'     => '[email protected]',
    'active'    => 2
]);

factory(Forum::class)->create();

$response = $this->actingAs($user)->json('POST', '/api/message', [
    'forum_id'      => 1,
    'subject'         => 'test',
    'message'       => 'test,'
]);

dd($response);

In the dd($response); I see that the request is unauthorized? Why is that in the docs I read that I can do it like this:

$this->actingAs($user)

I'm using Laravel 5.4 with Passport.

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

You may also specify which guard should be used to authenticate the given user by passing the guard name as the second argument to the actingAs method:

$this->actingAs($user, 'api')
1 like

Please or to participate in this conversation.