phplaravellaravel-bladerollbar

Logging a message in Rollbar makes php error disappear


I use Rollbar error monitoring and I get an error:

ErrorException: Undefined offset: 1

I can't really pin down the location of the error because it happens in the compiled code:

File /var/www/laravel/storage/framework/views/8d64d770d97f73443e576b8d42e0405f220c2c4e.php line 386

The blade.php page does not render.

However when I just put a statement:

 Log::info("im here!");

in an attempt to find the location, the page renders completely fine. The error in the rollbar log remains though.

What could be a smarter way to deal with this / find the reason for the error message ? :-)


Solution

  • ErrorException: Undefined offset: 1

    The error means that you're trying to access an array value by key 1 in your Blade template where no such key exists

    Find the code that looks like this $arrayName[1] 

    Make sure that your array isn't null and that it has at least two values in it (arrays are zero 0 indexed which means that 1 is the second value)

    And if the value on key 1 is optional, you can wrap the call with an if statement

    @if (array_key_exists(1, $arrayName)
        {{ $arrayName[1] }}
    @endif