Why ActingAs Not working in Laravel API Testing

3 years ago


You may come across this post because of your actingAs() is not working with Laravel API Testing. I discovered the error of why it was happening with me also.

In my case, I use a custom guard called jwt that was not using laravel actingAs() by default. That's why I always get 401 error, probably you too.

To address this issue, you need to pass the custom guard name, in my case, it was jwt.

$this->actingAs($user, 'jwt')->assetSuccess();

Hope it will work for you. :)

Thouhedu Islam Suchi

Thouhedul Islam

Laravel Developer

Hi, I am a Laravel Developer with a passion for web development. I specialize in PHP, particularly Laravel, as well as Javascript, MySql, and other cutting-edge web technologies.

During the day, I work for GLEIF, where I apply my skills and experience to develop innovative web applications. At night, I enjoy contributing to the community and solving problems. You can often find me on Laracasts, where I love to stay active and keep up-to-date with the latest trends in web development.

I am excited about the potential of technology and its power to transform people's lives.