danilchican's avatar

request()->route() is empty using phpunit test

Hi everyone! Laravel: 6.20

I need to test my GET http request but I faced with the issue related to request()->route() function call. I have a trait with custom boot method which is used in Post model. Inside boot method to apply a global scope or not I have a condition:

if(!request()->routeIs('admin.*')) {
         static::addGlobalScope('published', function (Builder $builder) {
            $builder->published();
        });
}

Everything works fine while I'm going through browser to get non-filtered posts in admin dashboard.

But in my http test there is a problem that request()->route() inside that check returns null.

How can I fix that to do not disable global scope at all? Thanks in advance!

0 likes
0 replies

Please or to participate in this conversation.