Using QueryBuilder with DB::connection(connection_name)->table(table_name) #937
Replies: 1 comment
-
QueryBuilder::for expects to receive a Illuminate\Database\Eloquent\Builder. I tried to make a workaround using new Builder(DB::table('table_name')) since it returns a Eloquent\Builder, but it doesn't work either, it returns the error "Call to a member function qualifyColumn() on null". This happens because Eloquent Builder (Illuminate\Database\Eloquent\Builder) is designed to work with Eloquent Models, which contain important metadata such as column definitions and database relationships. When you try to create an Eloquent\Builder directly from a Query\Builder, it expects certain functionalities, like column qualification, to be available from a Model. The issue here is that when you pass a Query\Builder directly to the Eloquent\Builder, Laravel expects an associated Model to provide the necessary context (such as the table name, columns, and relationships). The qualifyColumn() method is one of those that depend on a Model, which is why it fails when the Model is null. So, in the end, the only way to work with QueryBuilder::for is through Eloquent Models. |
Beta Was this translation helpful? Give feedback.
-
i am trying to use QueryBuilder with my second database
my query look like this
but i got error
Subject class
Illuminate\Database\Query\Builder
is invalid.Beta Was this translation helpful? Give feedback.
All reactions