Search code examples
laravelvoyager

Laravel Voyager Belongs To relationship in form displays “Searching”


Version information

Laravel: v7.26.1

Voyager: v1.4.2

PHP: 7.4.5

Database: MySQL 7.4.8

Description

I'm trying to solve one problem but I'm not doing well. There are 2 tables:

table1 (id, nameInTable1, active, create_at, update_at)

table2 (id, nameInTable1, nameInTable2, active, create_at, update_at)

I made a BREAD for both tables. I can now enter data via the form (and it works) in both tables. However, I wanted to add that in the second table I put "select" over the form so that I could select the names from the first table via the drop-down list.

When I followed the documentation and the video, and when I followed the steps, the data from the first table does not appear in the drop-down list when I fill in the second.

Steps To Reproduce

Here is a concrete example:

This is what Table 1 looks like

reklamekonvencija (id, konvencijanaziv, aktivan, created_at, updated_at)

The model for this table looks like the image below

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;


class Reklamekonvencija extends Model
{
    protected $table = 'reklamekonvencija';
    protected $fillable = ['id','konvencijanaziv','aktivan','created_at','updated_at']; 
    
    public function scopeActive($query)
    {
        return $query->where('aktivan', 1);
    }
    public function scopeInactive($query)
    {
        return $query->where('aktivan', 0);
    }
    
}

And BREAD looks like this:

BREAD of table 1

And this is what Table 2 looks like

reklame (id konvencijanaziv oglasivac nazivReklame nazivDelaMuzike autor trajanje created_at updated_at)

This is what the model looks like:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;


class Reklame extends Model
{
    protected $table = 'reklame';
    protected $fillable = ['id','konvencijanaziv', 'oglasivac', 'nazivReklame', 'nazivDelaMuzike', 'autor', 'trajanje', 'created_at', 'updated_at'];

    public function scopeActive($query)
    {
        return $query->where('aktivan', 1);
    }
    public function scopeInactive($query)
    {
        return $query->where('aktivan', 0);
    }
    
}

This is what BREAD for Table 2 looks like:

BREAD of table 2

When I want to insert the data in Table 2 now, it looks like this:

Add from drop down

The data in Table 1 do not appear in the drop-down list, although they do exist.

I folow the instruction from the site, and i followed the instructions of other people, mostly the steps are similar, but to do it still doesn't work..

Do you have any advice in which direction to look where I might be wrong?

Thank you.


Solution

  • I found a problem. I didn't pay attention to the fact that my ad block was turned on, it was causing a problem with the search, so it just pointed to "search" in the field where it was supposed to show the list of names from the other table.