Kyslik / column-sortable

Package for handling column sorting in Laravel 5/6/7/8
MIT License
644 stars 105 forks source link

Sortable does not work across related models using different databases #86

Closed wasxxm closed 6 years ago

wasxxm commented 6 years ago

Change columnExists method in Sortable.php from:

    {
        return (isset($model->sortable)) ? in_array($column, $model->sortable) :
            Schema::hasColumn($model->getTable(), $column);
    }

to the following to fix this issue.

   private function columnExists($model, $column)
    {
        return (isset($model->sortable)) ? in_array($column, $model->sortable) :
            Schema::connection($model->getConnectionName())->hasColumn($model->getTable(), $column);
    }
Kyslik commented 6 years ago

Never needed to work with multiple connections, thanks for the report + possible fix, will incorporate in future release