Voyager: [BUG] Undefined index: relationship_key

Created on 19 Feb 2019  ·  15Comments  ·  Source: the-control-group/voyager

Version information

  • Laravel: v5.7.24
  • Voyager: v1.1
  • PHP: 7.2.4
  • Database: MySQL 5.7.22

Description


When submitting an edit of a BREAD with a relationship I (sometimes) get the following error:
Undefined index: relationship_key_topic_belongstomany_topic_relationship

In DataType.php this key value will be set according to the relationship. Which in my case is topic_belongstomany_topic_relationship.

When inspecting the requestData. The realtionship_key_xxx index is sometimes set and sometimes it's not. (hence the error)

Steps to reproduce

Not really helpfull, but this is what I'm doing:

  1. Select edit BREAD
  2. Submit form
  3. See whether the update works or not

Expected behavior

The expected behavior is that this index (relationship_key_xxx) is set in the $requestData. Sometimes this is the case and sometimes it's not.

Screenshots

screenshot 2019-02-19 at 16 56 09

Additional context

This relationship is a relationship on the table itself. (A topic will show multiple topics and a topic can appear on multiple other topics as well).

I have made 2 models which reference Topic so I can get the related Topics to a certain Topic.

1 model under App\Models\Voyager\Topic (created by Voyager itself)

<?php

namespace App\Models\Voyager;

use Illuminate\Database\Eloquent\Model;
use TCG\Voyager\Traits\Translatable;

class Topic extends Model
{   
    use Translatable;

    protected $table = "topics";

    protected $translatable = [
        "title",
        "intro",
        "content_title",
        "content_sub_title",
        "content",

    ];

    protected $with = ['translations'];

    public function topics()
    {
        return $this->belongsToMany("App\Models\Topic", 'topics_related_topics', 'topic_id', 'related_topic_id');
    }
}

1 model under App\Models\Topic (self created to create a belongsToMany relationship)

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Topic extends Model
{
    protected $table = "topics";

    public function topics()
    {
        return $this->belongsToMany("App\Models\Voyager\Topic", 'topics_related_topics', 'related_topic_id', 'topic_id');
    }
}

bug

Most helpful comment

@webmasterscity you only needed the last command and your error was caused by view not being updated, it's not related to this issue even if the error is similar.

All 15 comments

What does $requestData show you?
Is it maybe quite big and it gets cutted because of post_max_size (doubt that tho)?
Is there any pattern on when it happens and when not?
The input itself is here:
https://github.com/the-control-group/voyager/blob/f078b6f5ff92b110b7bc2b67c2ab1a9a2faa066b/resources/views/tools/bread/relationship-partial.blade.php#L82

@emptynick Thanks for the reply!

The $requestData contains the following:

array:173 [▼
  "id" => "50"
  "_method" => "PUT"
  "_token" => "5Ry7Xixx1HVvINDFKwpwWyUvhYLXoofK1pQr5N0d"
  "name" => "topics"
  "display_name_singular" => "Topic"
  "display_name_plural" => "Topics"
  "slug" => "topics"
  "icon" => "voyager-news"
  "model_name" => "App\Models\Voyager\Topic"
  "controller" => null
  "policy_name" => null
  "generate_permissions" => "on"
  "server_side" => "on"
  "order_column" => null
  "order_display_column" => null
  "order_direction" => "asc"
  "default_search_key" => null
  "description" => null
  "field_required_id" => "1"
  "field_order_id" => "1"
  "field_id" => "id"
  "field_input_type_id" => "text"
  "field_display_name_id" => "Id"
  "field_details_id" => "{}"
  "field_required_title" => "0"
  "field_order_title" => "2"
  "field_browse_title" => "on"
  "field_read_title" => "on"
  "field_edit_title" => "on"
  "field_add_title" => "on"
  "field_delete_title" => "on"
  "field_title" => "title"
  "field_input_type_title" => "text"
  "field_display_name_title" => "Titel"
  "field_details_title" => "{}"
  "field_required_intro" => "0"
  "field_order_intro" => "3"
  "field_read_intro" => "on"
  "field_edit_intro" => "on"
  "field_add_intro" => "on"
  "field_delete_intro" => "on"
  "field_intro" => "intro"
  "field_input_type_intro" => "text_area"
  "field_display_name_intro" => "Intro"
  "field_details_intro" => "{}"
  "field_required_image" => "0"
  "field_order_image" => "4"
  "field_read_image" => "on"
  "field_edit_image" => "on"
  "field_add_image" => "on"
  "field_delete_image" => "on"
  "field_image" => "image"
  "field_input_type_image" => "image"
  "field_display_name_image" => "Afbeelding"
  "field_details_image" => "{}"
  "field_required_author" => "0"
  "field_order_author" => "5"
  "field_browse_author" => "on"
  "field_read_author" => "on"
  "field_edit_author" => "on"
  "field_add_author" => "on"
  "field_delete_author" => "on"
  "field_author" => "author"
  "field_input_type_author" => "text"
  "field_display_name_author" => "Auteur"
  "field_details_author" => "{}"
  "field_required_author_image" => "0"
  "field_order_author_image" => "6"
  "field_read_author_image" => "on"
  "field_edit_author_image" => "on"
  "field_add_author_image" => "on"
  "field_delete_author_image" => "on"
  "field_author_image" => "author_image"
  "field_input_type_author_image" => "image"
  "field_display_name_author_image" => "Auteur Afbeelding"
  "field_details_author_image" => "{}"
  "field_required_slug" => "0"
  "field_order_slug" => "7"
  "field_browse_slug" => "on"
  "field_read_slug" => "on"
  "field_edit_slug" => "on"
  "field_add_slug" => "on"
  "field_delete_slug" => "on"
  "field_slug" => "slug"
  "field_input_type_slug" => "text"
  "field_display_name_slug" => "Slug"
  "field_details_slug" => "{}"
  "field_required_active" => "0"
  "field_order_active" => "8"
  "field_browse_active" => "on"
  "field_read_active" => "on"
  "field_edit_active" => "on"
  "field_add_active" => "on"
  "field_delete_active" => "on"
  "field_active" => "active"
  "field_input_type_active" => "checkbox"
  "field_display_name_active" => "Actief"
  "field_details_active" => "{"on":"Aan","off":"Uit","checked":"false"}"
  "field_required_content_title" => "0"
  "field_order_content_title" => "9"
  "field_read_content_title" => "on"
  "field_edit_content_title" => "on"
  "field_add_content_title" => "on"
  "field_delete_content_title" => "on"
  "field_content_title" => "content_title"
  "field_input_type_content_title" => "text"
  "field_display_name_content_title" => "Content Titel"
  "field_details_content_title" => "{}"
  "field_required_content_sub_title" => "0"
  "field_order_content_sub_title" => "10"
  "field_read_content_sub_title" => "on"
  "field_edit_content_sub_title" => "on"
  "field_add_content_sub_title" => "on"
  "field_delete_content_sub_title" => "on"
  "field_content_sub_title" => "content_sub_title"
  "field_input_type_content_sub_title" => "text"
  "field_display_name_content_sub_title" => "Content Sub Titel"
  "field_details_content_sub_title" => "{}"
  "field_required_content" => "0"
  "field_order_content" => "11"
  "field_read_content" => "on"
  "field_edit_content" => "on"
  "field_add_content" => "on"
  "field_delete_content" => "on"
  "field_content" => "content"
  "field_input_type_content" => "rich_text_box"
  "field_display_name_content" => "Content"
  "field_details_content" => "{}"
  "field_required_created_at" => "0"
  "field_order_created_at" => "12"
  "field_browse_created_at" => "on"
  "field_read_created_at" => "on"
  "field_edit_created_at" => "on"
  "field_delete_created_at" => "on"
  "field_created_at" => "created_at"
  "field_input_type_created_at" => "timestamp"
  "field_display_name_created_at" => "Aangemaakt op"
  "field_details_created_at" => "{}"
  "field_required_updated_at" => "0"
  "field_order_updated_at" => "13"
  "field_updated_at" => "updated_at"
  "field_input_type_updated_at" => "timestamp"
  "field_display_name_updated_at" => "Aangepast op"
  "field_details_updated_at" => "{}"
  "field_required_active_home" => "0"
  "field_order_active_home" => "14"
  "field_browse_active_home" => "on"
  "field_read_active_home" => "on"
  "field_edit_active_home" => "on"
  "field_add_active_home" => "on"
  "field_delete_active_home" => "on"
  "field_active_home" => "active_home"
  "field_input_type_active_home" => "checkbox"
  "field_display_name_active_home" => "Active Home"
  "field_details_active_home" => "{"on":"Aan","off":"Uit","checked":"false"}"
  "field_order_topic_belongstomany_topic_relationship" => "15"
  "field_browse_topic_belongstomany_topic_relationship" => "on"
  "field_read_topic_belongstomany_topic_relationship" => "on"
  "field_edit_topic_belongstomany_topic_relationship" => "on"
  "field_add_topic_belongstomany_topic_relationship" => "on"
  "field_delete_topic_belongstomany_topic_relationship" => "on"
  "field_display_name_topic_belongstomany_topic_relationship" => "Gerelateerde artikelen"
  "relationship_type_topic_belongstomany_topic_relationship" => "belongsToMany"
  "relationship_table_topic_belongstomany_topic_relationship" => "topics"
  "relationship_model_topic_belongstomany_topic_relationship" => "App\Models\Topic"
  "relationship_column_belongs_to_topic_belongstomany_topic_relationship" => "id"
  "relationship_column_topic_belongstomany_topic_relationship" => "id"
  "relationship_pivot_table_topic_belongstomany_topic_relationship" => "topics_related_topics"
  "relationship_label_topic_belongstomany_topic_relationship" => "title"
  "field_required_topic_belongstomany_topic_relationship" => "0"
  "field_input_type_topic_belongstomany_topic_relationship" => "relationship"
  "field_topic_belongstomany_topic_relationship" => "topic_belongstomany_topic_relationship"
  "relationships" => array:1 [▶]
]

I haven't altered the original post_max_size (and I never had this kind of error in previous Voyager projects).

There is no pattern either. Sometimes I have it in the $requestData and sometimes not (as you can see in the array above). Whether I change a simple BREAD-flag or display name, or just don't edit anything at all. Sometimes it's present and sometimes it's not.

The input itself is also present in the file you have specified. I haven't altered the edit-add.blade.php for the Voyager BREAD template either.

Right now I dont see anything with topic_belongstomany... in your request, so it _should_ be failing at line 182 already.
By the way: which browser are you using? Can you try if another browser helps?

Please check max_input_vars in php.ini file . The request input may be cut off because it might have crossed this limit. Try by increasing its value.

@emptynick You're right, I'm sorry, I wasn't updating the BREAD containing topic_belongstomany. I have updated my comment from the same BREAD of the question.

At that moment I was checking other BREADs with relations that's why I posted a different one. The issue still remains across BREADs with relations that the relationship_key_xxx sometimes doesn't show up in the $requestData.

The issue appears in Chrome, Safari and Firefox

@DrudgeRajen I have increased the value to 10000 (original 1000)

The problem still occurs

@emptynick While I was in the php.ini file I also increased the post_max_size (from 100 to 512M)

The problem still occurs

@DaveH-101 I had the same issue which was due to the max_input_vars configuration. I updated its value and restart the apache and it was working fine.

Closing due to inactivity.

А я нашел как этой ошибки избежать, нужно дожаться полноый загрузки старницы, чтобы в развернутом отношении было видно все поля. Тогда сохраняется нормально.

And I found how to avoid this error, you need to wait until the full loading of the page, so that the unfolded attitude was visible to all the fields. Then it remains normal.

@Roaderchik spasibo tovarisch, can confirm that this workaround (of just waiting for a while after page load basically) seems to work.
If I have a many-to-many relationship and try to edit something from BREAD quickly it seems to consistently fail. Maybe this helps in solving the issue.

Some ajax calls are triggerd to get tables information.
If not all ajax call are done before hitting save that error might happen.

I have the same problem when editing the relationship I need help

I made a PR to solve this issue but there are some html/css problems to be solved.
So if anyone has time and expertise can check #4716

Thanks

This worked for me:
php artisan vendor:publish --tag=voyager_assets --force
php artisan view:clear

@webmasterscity you only needed the last command and your error was caused by view not being updated, it's not related to this issue even if the error is similar.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kevinjon27 picture kevinjon27  ·  3Comments

abacram picture abacram  ·  3Comments

popica80 picture popica80  ·  3Comments

winex01 picture winex01  ·  3Comments

MikadoInfo picture MikadoInfo  ·  3Comments