Voyager: "Undefined property" when removing select dropdown option

Created on 24 Mar 2017  路  10Comments  路  Source: the-control-group/voyager

  • Laravel Version: 5.4.x
  • Voyager Version: 0.11.7
  • PHP Version: 7.1.1
  • Database Driver & Version: MySQL X

Description:

When you have a BREAD row using the Select Dropdown type, it give problems handling the options when a option is removed.

Steps To Reproduce:

Make BREAD with a Select Dropdown row and the following settings:

{
    "default": "Foo",
    "options": {
        "foo": "Foo",
        "bar": "Bar"
    }
}

Then create a new row with this set as Foo.
Then edit the BREAD settings to:

{
    "default": "Bar",
    "options": {
        "bar": "Bar"
    }
}

Then go back to the row for that BREAD and it will throw the following error:

ErrorException in 1dc0155360549e4cd7aacdfed574eebe6a05f97e.php line 68:
Undefined property: stdClass::$foo (View: /site.dev/vendor/tcg/voyager/resources/views/bread/browse.blade.php)

Solution

My idea for a solution is to show the default option if the option no longer exists.

bug

Most helpful comment

Duplicating my comment from #1639 in case it helps:

For me this error was solved with the exclusion of a null value on the obj:-

/vendor/tcg/voyager/resources/views/bread/browse.blade.php

Line 118
@unless(empty($options->options->{$data->{$row->field}}))
     {!! $options->options->{$data->{$row->field}} !!}
@endunless

*Edit: Let me know if it solves for you and I will submit PR *

All 10 comments

This happens also when adding more options. It doesn't update correctly in database. If you delete the data entry from data_rows table even if it seems updated and save your bread again it works great. Don't know why yet

Can someone confirm that this already fixed in 1.0 ?

@handiwijoyo it's not fixed so far.

Duplicating my comment from #1639 in case it helps:

For me this error was solved with the exclusion of a null value on the obj:-

/vendor/tcg/voyager/resources/views/bread/browse.blade.php

Line 118
@unless(empty($options->options->{$data->{$row->field}}))
     {!! $options->options->{$data->{$row->field}} !!}
@endunless

*Edit: Let me know if it solves for you and I will submit PR *

Yes that indeed works.
Alternatively we could use {!! $options->options->{$data->{$row->field}} or '' !!}

@dhonions Do you want to submit a PR for this?

@emptynick Yes, please do.

@dhonions Superb work! Issue fixed. PR!

Hi, for me this error was solved with

{!! $options->options->{$data->{$row->field}} or $data->{$row->field} !!}
parent_drop_down

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vaggelis2018 picture vaggelis2018  路  3Comments

craigb88 picture craigb88  路  3Comments

TXRRNT picture TXRRNT  路  3Comments

winex01 picture winex01  路  3Comments

ferrywae picture ferrywae  路  4Comments