Feature Toggle in laravel

Submitted by saeedvir - 5 years ago

for software different features and set Feature On/Off

create this file in laravel project:

config/features.php

<?php

return [
    'loginWithGoogle' => true,
    'newSearchBox' => true,
    'newsLetterBox' => false,
    /*
        Some Features ....

    */
];


then edit the AppServiceProvider and add this Blade Code in boot() function :
    
        Blade::if('feature', function ($feature) {
            return config("features.$feature", false);
        });
        

done !

you can use this code in blade files (Views):
    
@feature('loginWithGoogle')
    <a href="#" class="btn btn-primary-soft">
        <i class="fa fa-google"></i>
        <span>Login With Google</span>
    </a>
@endfeature