0

i have a version of laravel 8x jetstream with fortify on a test server and a production server.

test: prj_l8xtest.com production: prj_l8xprod.com

I wanted to activate or deactivate some pages made available by fortify, they can be activated or deactivated from here -> prj_l8xlocal/config/fortify.php:

.
.   
.
.
'features' => [
    Features::registration(),
    Features::resetPasswords(),
    Features::emailVerification(),
    Features::updateProfileInformation(),
    Features::updatePasswords(),
    Features::twoFactorAuthentication([
        'confirmPassword' => true,
    ]),
],

I would like to activate or deactivate some of these pages depending on test or production.

i think i could do it all with an if(){} which checks url in question (production or test), but i would have no idea how to take url. Or are there better solutions than my proposal?

  • I think you can do this in a service provider and setting the config values (as shown in https://laravel.com/docs/8.x/configuration#accessing-configuration-values) in code. Need to make sure it runs before the fortify service provider (if any) – apokryfos Nov 16 '20 at 00:31
  • how can i put an if condition inside the fortify file? if I put an if inside an array it obviously gives me an error @apokryfos or how can I load a condition in the boot of the service provider? telling him if there is this url activates these fortify pages otherwise these others? – Gianmarco Gagliardi Nov 17 '20 at 16:54

1 Answers1

0

The config file is normal PHP so you can write a normal PHP script in it and then return the result if you want. However the problem is that the request information is not loaded when the config is first read which is why I recommended a service provider to modify the config values in the boot method. You can try adding the following in your AppServiceProvider in the boot method:

public function boot() {
   // other boot code
   if (app()->environment('production')) {
      config([ 'fortify.features' => array_merge(config('fortify.features'), [
            // production only features
      ]);
   }
}

Be aware that not all the request information might be available at this point so you may need to directly access $_SERVER variables to find what you need.

apokryfos
  • 38,771
  • 9
  • 70
  • 114