thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.78k stars 2.67k forks source link

Other model's path don't work!! #5180

Open Vasiliy-Makogon opened 3 years ago

Vasiliy-Makogon commented 3 years ago

Version information

Description

Hi. We are using voyager and our tables location in two different databases. Every model extends from abstract model, who extends by typical Eloquent Model:

abstract class AbstractModel extends Model
{
    protected $connection = "blablabla"; // for other clsses this use other database connections name

    public function getTable()
    {
        $table = parent::getTable();

        if (strpos($table, '.') !== false) {
            return $table;
        }

        $table = $this->getConnection()->getDatabaseName() . ".$table";

        return $table;
    }
}

If table has database prefix, BREAD is crushed. On page "/edit" empty content in section "Edit the rows for the incident_control_statuses table below:"

BREADs dont work with full path name table, when id path includes database name.


UPD/Solution: Problem in this method: \TCG\Voyager\Database\Schema\SchemaManager::listTableDetails at line 56:

$columns = static::manager()->listTableColumns($tableName);

you must search first part in $tableName and call method as:

if (!strstr($tableName, '.')) {
    $tableName = ".$tableName";
}

list($scheme, $table) = array_pad(explode('.', $tableName, 2), 2, null);

$columns = static::manager()->listTableColumns($table, $scheme);
mohsen2986 commented 3 years ago

be sure the model path is correct in laravel 8 models are in

app\Models\YourModel