jikan-rest/app/Concerns/FilteredByLetter.php
pushrbx a145f18bbd wip - major refactor
- AppServiceProvider is needs more work to wire in new services
- todo: more dtos
- todo: add unit tests
- todo: add more integration tests
2023-05-21 11:14:34 +01:00

34 lines
865 B
PHP

<?php
namespace App\Concerns;
trait FilteredByLetter
{
/**
* The name of the field which contains the display name of the record.
* @var ?string
*/
protected ?string $displayNameFieldName;
/** @noinspection PhpUnused */
public function filterByLetter(\Laravel\Scout\Builder|\Illuminate\Database\Eloquent\Builder $query, string $value): \Laravel\Scout\Builder|\Illuminate\Database\Eloquent\Builder
{
if (empty($this->displayNameFieldName)) {
return $query;
}
return $query->where($this->displayNameFieldName, "like", "{$value}%");
}
public function getDisplayNameFieldName(): string
{
return $this->displayNameFieldName;
}
public function displayNameFieldName(string $name): self
{
$this->displayNameFieldName = $name;
return $this;
}
}