voyager: [BUG] Undefined index: relationship_key

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');
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (3 by maintainers)

Commits related to this issue

Most upvoted comments

@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.

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

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

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.

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