简体   繁体   中英

activate some fortify pages for production and others for testing

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM