So $permittedTables
is an array of tablenames which I want to join to coretable
. To do this, I want to use Model::with(), like so:
$join = coretable::with($permittedTables)->get();
However, I get this error when executing the above code:
Argument 1 passed to Illuminate\Database\Eloquent\Builder::parseWithRelations() must be of the type array, object given, called in E:\aether-backend\vendor\illuminate\database\Eloquent\Builder.php on line 1043
Whats confusing me the most is the fact this actual IS an array, so I dont really understand why it actually throws THIS error xD
Still, can anyone tell me if this approach is actually possible? And if so, how can I do it?
EDIT: This is how the array was generated:
$permittedTables = extensiontables_registry::findmany($ids)->pluck('extensiontable_name');
Just in case this has anything to do with it.
The pluck
function return Collection/Enumerable, you have to call toArray
function to get array of table names
$permittedTables = extensiontables_registry::findmany($ids)
->pluck('extensiontable_name')
->toArray();
$permittedTables = extensiontables_registry::findmany($ids)->pluck('extensiontable_name');
In above code fragment ->pluck()
method returns Object, that's why it throws following error must be of the type array, object given
Try using this: $permittedTables = extensiontables_registry::findmany($ids)->pluck('extensiontable_name')->toArray()
It should work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.