bezhanSalleh / filament-exceptions

A Simple & Beautiful Pluggable Exception Viewer for FilamentPHP's Admin Panel
MIT License
143 stars 22 forks source link

Unsupported operand types: string + int #58

Open victorhbbergamo opened 2 months ago

victorhbbergamo commented 2 months ago

Description

Steps to reproduce the bug:

Use named bindings in a database query, for example:

DB::select('select * from users where id = :id', bindings: ['id' => 1])

In my case, I have a stored procedure in another Oracle OCI connection that is called in the same manner, using named bindings.

When there is a query error, the package saves the bindings, but within resources/components/query-preview.blade.php, there is a section of code that retrieves the key and adds 1:

...
@foreach ($query['bindings'] as $key => $value)
    <div class="flex px-4 py-2">
        <div class="py-2 font-mono text-gray-500 basis-1/12 dark:text-gray-400">
            {{ $key + 1 }}
        </div>
        <div
            class="px-4 py-2 font-medium text-gray-500 rounded-lg basis-11/12 dark:text-gray-200 bg-gray-950/5 dark:bg-white/5">
            {{ $value }}
        </div>
    </div>
@endforeach
...

Since the key is a string due to the named bindings, this results in an "Unsupported operand types: string + int" error.

Expected behavior:

The component should handle named bindings correctly without throwing an error.

Current behavior:

The application throws an "Unsupported operand types: string + int" error when named bindings are used and the key is a string.

Package version:

"bezhansalleh/filament-exceptions": "^2.1"

Environment:

PHP: 8.2.1 Laravel: 10.48.14 Operating System: WSL with Ubuntu 20.04

Pull Request Suggestion

To fix this issue, I suggest adding a validation to check if the key is an integer before performing the addition. Here is the proposed change:

File: resources/components/query-preview.blade.php

...
@foreach ($query['bindings'] as $key => $value)
    <div class="flex px-4 py-2">
        <div class="py-2 font-mono text-gray-500 basis-1/12 dark:text-gray-400">
            {{ is_int($key) ? ($key + 1) : $key }}
        </div>
        <div
            class="px-4 py-2 font-medium text-gray-500 rounded-lg basis-11/12 dark:text-gray-200 bg-gray-950/5 dark:bg-white/5">
            {{ $value }}
        </div>
    </div>
@endforeach
...

This modification ensures that if the key is an integer, it will be incremented by 1. If it is a string, it will be displayed as-is, preventing the "Unsupported operand types: string + int" error.

Feel free to adapt this to better fit the style and requirements of your bug report and pull request.

victorhbbergamo commented 2 months ago

Expected result:

image