Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jul 6, 2021
1 parent 7b0235c commit 19cff04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 41 deletions.
48 changes: 20 additions & 28 deletions src/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,26 @@ public function unsearchable()
$this->newCollection([$this])->unsearchable();
}

/**
* Determine if the model existed in the search index prior to an update.
*
* @return bool
*/
public function wasSearchableBeforeUpdate()
{
return true;
}

/**
* Determine if the model existed in the search index prior to deletion.
*
* @return bool
*/
public function wasSearchableBeforeDelete()
{
return true;
}

/**
* Get the requested models from an array of object IDs.
*
Expand Down Expand Up @@ -364,32 +384,4 @@ protected static function usesSoftDelete()
{
return in_array(SoftDeletes::class, class_uses_recursive(get_called_class()));
}

/**
* Was the model searchable before the update happened?
*
* @return bool
*/
public function wasSearchableBeforeUpdate(): bool
{
return (clone $this)->forceFill($this->getOriginal())->shouldBeSearchable();
}

/**
* Was the model searchable before the deletion happened?
*
* To be used only when the model gets deleted using `delete`.
*
* @return bool
*/
public function wasSearchableBeforeDelete(): bool
{
if (! method_exists($this, 'getDeletedAtColumn')) {
return $this->shouldBeSearchable();
}

return (clone $this)->forceFill([
$this->getDeletedAtColumn() => null,
])->shouldBeSearchable();
}
}
13 changes: 0 additions & 13 deletions tests/Feature/SearchableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,6 @@ public function test_was_searchable_on_model_without_soft_deletes()
$this->assertTrue($model->wasSearchableBeforeDelete());
}

public function test_was_searchable_before_update_works_from_false_to_true()
{
$model = new SearchableModelWithSoftDeletes([
'published_at' => null,
]);
$model->syncOriginal();

$model->published_at = now();

$this->assertFalse($model->wasSearchableBeforeUpdate());
$this->assertTrue($model->shouldBeSearchable());
}

public function test_was_searchable_before_update_works_from_true_to_false()
{
$model = new SearchableModelWithSoftDeletes([
Expand Down

0 comments on commit 19cff04

Please sign in to comment.