Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
Update WhereNot.php
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Dec 9, 2020
1 parent bd3ecf8 commit 06313b7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/WhereNot.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ public static function addMacro(string $name = 'whereNot')
// Create a new Eloquent Query Builder with the given Query Builder and
// set the model from the original builder.
$query = new Builder($query);
$query->setModel($builder->getModel());
$query->setModel($model = $builder->getModel());

$originalTable = $query->getModel()->getTable();
$qualifiedKeyName = $model->getQualifiedKeyName();
$originalTable = $model->getTable();

// Instantiate a new model that uses the aliased table.
$aliasedTable = WhereNot::getTableAlias($originalTable);
Expand All @@ -106,7 +107,7 @@ public static function addMacro(string $name = 'whereNot')
->setModel($aliasedModel)
->select(DB::raw(1))
->from($originalTable, $aliasedTable)
->whereColumn($aliasedModel->getQualifiedKeyName(), 'posts.id')
->whereColumn($aliasedModel->getQualifiedKeyName(), $qualifiedKeyName)
->limit(1)
->tap(fn ($query) => $callable($query));
});
Expand Down

0 comments on commit 06313b7

Please sign in to comment.