Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kay899's avatar

Problem with: Undefined index

Hi,

I have a very special problem since a few days.

For my Models I have a configuration file with some special definitions for e.g. properties:

http://laravel.io/bin/wJGzL

So, there I define e.g. the array that contains the values for showing which checkboxes are checked for a checkbox area:

'series' => array( 'label' => 'character.series',
'form' => array( 'checked' => 'rel_series',

In my Form, I can access all these values with

$properties[$property]['form']['checked']

which then shows: rel_series. ok so good.

If I dd() $item->$properties[$property]['form']['checked'] I'll get: array(2) { [0]=> int(1) [1]=> int(7) } which is what I expect.

Now I would like to check if a checkbox needs to be checked and I'll do this:

http://laravel.io/bin/qQkPR

then I'll get this error:

Undefined index: checked (View: C:\xampp\htdocs\stargate\app\views\admin_formfields.blade.php)

What is my problem here that the dump is showing correct data and when I try to use it, it is not working?

Hope someone has an idea what I can do?

I cannot try to access to this array in another way, as my whole system is working like that.

Thanks Andreas

0 likes
3 replies
fenos's avatar

If you are checking this trough a loop, it's really possible that one or more form array doesn't have the checked index ( how the error say) try to change the if statement like so:

@if ( array_key_exists('checked',$item->$properties[$property]['form']) and 
       in_array($checkbox->id, array($item->$properties[$property]['form']['checked'])) )

@else
 // else
@endif
kay899's avatar

hey,

sounds like a goodf idea, but when I do it like

                    @if ( array_key_exists('checked',$item->$properties[$property]['form']) && in_array($checkbox->id, $item->$properties[$property]['form']['checked']) )
                        {{ Form::checkbox($properties[$property]['form']['prefix'].'[]', $checkbox->id, true) }}
                    @else
                        {{ Form::checkbox($properties[$property]['form']['prefix'].'[]', $checkbox->id, false) }}
                    @endif

I'll get this error:

Array to string conversion (View: C:\xampp\htdocs\stargate\app\views\admin_formfields.blade.php)

Any idea? Thanks Andreas

nolros's avatar

Array to string conversion means you are passing an array vs. an array element for view output. Example, you cannot

$property['form']

What is the .'[]' after ['prefix']? Are you attempting to concat two array?

Please or to participate in this conversation.