Skip to content

[Bug]: Builder does not support BelongsToMany #2176

@mbrioski

Description

@mbrioski

What happened?

It seems that the relation of type BelongsToMany is not supported in the builder method:
public function builder(): Builder

In fact, debugging the code i can see in Rappasoft\LaravelLivewireTables\Traits\WithData

protected function getTableForColumn(Column $column): ?string
    {
        $table = null;
        $lastQuery = clone $this->getBuilder();

        foreach ($column->getRelations() as $relationPart) {
            $model = $lastQuery->getRelation($relationPart);

            if ($model instanceof HasOne || $model instanceof BelongsTo || $model instanceof MorphOne) {
                $table = $this->getTableAlias($table, $relationPart);
            }

            $lastQuery = $model->getQuery();
        }

        return $table;
    }

It seems that if i have a BelongsToMany relation, what i get is the data of the model of the query

How to reproduce the bug

No response

Package Version

^3.5

PHP Version

8.3
None

Laravel Version

v11.12.0
No response

Alpine Version

No response

Theme

None

Notes

No response

Error Message

Rappasoft\LaravelLivewireTables\Views\Column::setTable(): Argument #1 ($table) must be of type string, null given, called in /var/www/html/portal/vendor/rappasoft/laravel-livewire-tables/src/Traits/Helpers/ColumnHelpers.php on line 43

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions