I need to make my routes conditional, based on config:
//routes/auth.php
if (config('auth.allow_registration')) {....
The above config param is set in the config file:
//config/auth.php
'allow_registration' => false,
It is all working fine, until I try to unit-test it
public function test_registration_screen_can_be_rendered()
{
config()->set('auth.allow_registration', true);
$response = $this->get('/register');
$response->assertStatus(200);
}
The test case is failing.
I understand that after I change config, I need to reread routes. But how?
I found only this $this->refreshApplication();
it suppose to reread routes, but it also rereads the config.
How can I only reread routes, but keep my modified config intact?
You can use a middleware on routes witch you want to have conditions for access. then you can just use the middleware on the route or in your controller. you can learn about it in Laravel good documentation here.