We need to eneble/disable Laravel debugbar depending on IP address. It works if we clear/disable the caching.
But it does not work when caching enabled. here is my code
//Enabling DEBUGBAR in Production Only for developers
if(in_array($request->ip(), [ip addresses])) {
config(['app.debug' => true]);
}
.env
APP_DEBUG=false
We are using configuration and route caching. What would be the best way to achieve this?
Laravel version - 5.4
Debugbar version - 2.2
Debugger has functionality to enable/disable it at runtime :
\Debugbar::enable();
\Debugbar::disable();
If you want to use the debugbar in production, disable in the config and only enable when needed.
So you can do :
if(in_array($request->ip(), [ip addresses])) {
\Debugbar::enable();
// Forcing the cache to be cleared
// Not recommended but if and only if required
\Artisan::call('cache:clear');
}
Please check documentation for more help.
You are using Debugbar
library so this library will be loaded before your route or controller loaded, so better you have to bootstrap your stuffs before the library loaded. Then we can bootstrap our custom configuration in the AppServiceProvider
class.
Service providers are the central place of all Laravel application bootstrapping.
Simple Method:
Change the file app\Providers\AppServiceProvider.php
class according to the below code.
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Request;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
// You can also clear cache if needed Artisan::call('cache:clear');
if(in_array(Request::ip(), ['127.0.0.1'])) {
config(['app.debug' => true]);
}
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
}
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