Skip to content

Commit

Permalink
Use Laravel model ie. boot when importing models...
Browse files Browse the repository at this point in the history
  • Loading branch information
stokic authored Jul 5, 2023
1 parent c4258c3 commit d926f3a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Console/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down

0 comments on commit d926f3a

Please sign in to comment.