I'm building a Laravel app, which has a number of various features. I want to be able to enable or disable them depending on a particular domain's requirement. Currently, I have in my config a series of flags such as:
'is_feature_1_enabled' => true,
'is_feature_2_enabled' => false,
... and so on.
Then in my controllers and views, I check those config values to see whether or not I should be displaying something, allowing certain actions, etc. My app is starting to get polluted with these kinds of checks everywhere.
Is there a best practice method of managing features in a Laravel app?
Open the app. php file located in your config/app. php laravel project. Search for debug key and change true to enable debug mode and false for disabling debug mode default it will show false.
Show activity on this post. I am using this command to enable maintenance mode php artisan down --secret="1630542a-246b-4b66-afa1-dd72a4c43515 . And then, I access my site with exapmple.com/1630542a-246b-4b66-afa1-dd72a4c43515 , to bypass the maintenance mode.
What is maintenance mode? Maintenance mode in Laravel prevents users from accessing the application. This is usually done when you want to carry out an update, upgrade, or debug errors from the application. You can set your application to maintenance mode by running the following command: php artisan down.
Open the command prompt or terminal based on the operating system you are using and type the following command to create controller using the Artisan CLI (Command Line Interface). Replace the <controller-name> with the name of your controller. This will create a plain constructor as we are passing the argument — plain.
This is technically called feature flags - https://martinfowler.com/articles/feature-toggles.html
depends on your requirements, flags in config/database, rollout, etc...
But it's basically if's in code and cannot be clean.
Laravel packages:
https://github.com/alfred-nutile-inc/laravel-feature-flag
https://github.com/francescomalatesta/laravel-feature
Some services:
https://launchdarkly.com/
https://bullet-train.io/
https://configcat.com/
Also look at https://marketingplatform.google.com/about/optimize/ for frontend.
I've encountered the same problem when I tried to implement multiple hotel providers.
What I did was using service container.
first you will create class for each domain With his features:
then you gonna use binding in your app service provider to bind the domain with class to use.
$this->app->bind('Domain1',function (){
return new Domain1();
});
$this->app->bind('Domain2',function (){
return new Domain2();
});
Note you can use general class that holds the features goes with all domains then use that general class in your classes
Finally in your controller you can check your domain then to use the class you gonna use
app(url('/'))->methodName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With