Reputation: 3739
In Laravel 4, I want to set the configuration variable "debug" to "false" by default, but to "true" for requests from my own IP address (the test will eventually be more sophisticated than that).
Based on the documentation at http://four.laravel.com/docs/configuration, I've tried the following:
config/app.php:
'debug' => false
filters.app - App::before (I also tried putting the code at the top of routes.php, with the same effect):
if(Request::getClientIp() == '[my ip address]') {
echo 'hello world';
Config::set('app.debug', true);
}
echo Config::get('app.debug');
When I visit a bad URL I see "hello world" and "1", so that's good, but then just the public (non-debug) error message displays below that.
I understand config variables set at run-time are only for a single request, but since my "hello world" is displaying, it seems like this is a single request.
Is there a better place to put my code, or is what I'm doing not actually possible?
Upvotes: 1
Views: 6291
Reputation: 1683
After some digging into how the exception handler I've found this to be reliable:
Config::set('app.debug', true);
app()->startExceptionHandling();
Why this approach? Because Laravel binds the exception handler at startup (to avoid PHPs internal one ruining things) you'll need to fake a reboot of that part.
PS. I'm reviving this old question because I don't think the accepted answer is accurate. It does not allow you to enable debugging at runtime, and I cannot detect whether the user is an employee by looking at system variables.
Upvotes: 2
Reputation: 1360
This seems like something you could accomplish with Laravel's environment detection (from the page you linked: http://four.laravel.com/docs/configuration#environment-configuration).
Using environments, you decide on a name—you could call yours debugging
—then you put config files for that environment in a subdirectory of your config directory. So in the case you gave above, you'd copy the app.php
config file to /app/config/debugging/app.php
(and any others you wanted to), and make the necessary configuration changes.
Then the important step is to detect the environment so that your app will use the debugging
config files. This is specified in /bootstrap/start.php
. You can pass a closure instead of an array to Laravel's environment detection, and return the environment name you want to use, so you could use your approach from above like so:
$env = $app->detectEnvironment(function()
{
if ($_SERVER['REMOTE_ADDR'] === '[my ip address]') {
return 'debugging';
}
});
I haven't tested it, but it should work. Hope that helps!
Upvotes: 4