From d926f3a4fa3d91f7998ff8b7b87369b757eaeb6b Mon Sep 17 00:00:00 2001 From: Sasa Tokic Date: Wed, 5 Jul 2023 12:42:31 +0200 Subject: [PATCH] Use Laravel model ie. boot when importing models... --- src/Console/ImportCommand.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Console/ImportCommand.php b/src/Console/ImportCommand.php index 3fa61b2..5d6d944 100644 --- a/src/Console/ImportCommand.php +++ b/src/Console/ImportCommand.php @@ -56,14 +56,22 @@ public function handle(Dispatcher $events) $fields = array_intersect($desiredColumns, $availableColumns); - $query = $db->table($model->getTable()); + $query = $model::query(); if ($fields) { $query->select($model->getKeyName()) ->addSelect($fields); } - $indexer->query($query->toSql()); + $sql = $query->toSql(); + $bindings = $query->getBindings(); + + foreach ($bindings as $binding) { + $value = is_numeric($binding) ? $binding : "'{$binding}'"; + $sql = preg_replace('/\?/', $value, $sql, 1); + } + + $indexer->query($sql); $indexer->run(); $this->info('All ['.$class.'] records have been imported.');