Skip to content

Commit

Permalink
Allow overwritting of soft deleted Eloquent model records
Browse files Browse the repository at this point in the history
  • Loading branch information
DivineOmega committed May 21, 2020
1 parent 3d7a04e commit 7243386
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Objects/Destinations/EloquentDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DivineOmega\uxdm\Interfaces\DestinationInterface;
use DivineOmega\uxdm\Objects\DataRow;
use Illuminate\Database\Eloquent\SoftDeletes;

class EloquentDestination implements DestinationInterface
{
Expand All @@ -16,11 +17,17 @@ public function __construct($eloquentModelClassName)

private function alreadyExists(array $keyDataItems)
{
$count = $this->model->where(function ($query) use ($keyDataItems) {
$query = $this->model->where(function ($query) use ($keyDataItems) {
foreach ($keyDataItems as $keyDataItem) {
$query->where($keyDataItem->fieldName, $keyDataItem->value);
}
})->count();
});

if (in_array(SoftDeletes::class, class_uses($this->model))) {
$query->withTrashed();
}

$count = $query->count();

return $count > 0;
}
Expand Down

0 comments on commit 7243386

Please sign in to comment.