Crud: Undefined index: value (When using select_from_array)

Created on 21 Dec 2016  路  6Comments  路  Source: Laravel-Backpack/CRUD

PHP: 7.0
Ubuntu 16.04 (regular LAMP)
Laravel: 5.3

I have two projects, backpack-demo and larafin (my own).

This is the code:

$this->crud->addField([ 
        'name' => 'isPaid',
        'label' => 'Paid',
        'type' => 'select_from_array',
    'options' => ['Yes' => 'Yes', 'No' => 'No'],
    'allows_null' => false,
]);

Works awesome on backpack-demo.

On my own project on the other hand I get this:

Undefined index: value (View: /var/www/html/larafin/vendor/backpack/crud/src/resources/views/fields/select_from_array.blade.php) (View: /var/www/html/larafin/vendor/backpack/crud/src/resources/views/fields/select_from_array.blade.php) (View: /var/www/html/larafin/vendor/backpack/crud/src/resources/views/fields/select_from_array.blade.php)

I wonder why.

Bug

Most helpful comment

I came across this the other day, a quick fix is to add an empty value param to your array going into the addField

All 6 comments

I came across this the other day, a quick fix is to add an empty value param to your array going into the addField

Huh, what you know, it works. Thanks.

I wonder why this is going on though. Maybe because backpack-demo uses 5.2 and I'm using 5.3?

Something funky is going on behind the scenes where on the "create" the value param doesn't exist, which causes some issues. It should exist I think but maybe @tabacitu can shed some light

Huh. Don't know, but I'll investigate and come back.

Error is thrown while checking is_array() method against key that is not set. Here is the exact line. Quick fix is to refactor it to something like this:
(isset($field['value']) && is_array($field['value']) && in_array($key, $field['value'])).

Fixed in 3.1.49 (https://github.com/Laravel-Backpack/CRUD/pull/341) thanks to Chris Thompson, using exactly @IvanBernatovic 's method.

Thanks guys, cheers!

P.S. I'll go ahead and close this issue so we don't clog the section. Feel free to open it again if you encounter problems or comment if you have follow-ups.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mklahorst picture mklahorst  路  3Comments

gotrecillo picture gotrecillo  路  3Comments

sokvebolkol picture sokvebolkol  路  3Comments

sonoftheweb picture sonoftheweb  路  3Comments

lotarbo picture lotarbo  路  3Comments