mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
- AppServiceProvider is needs more work to wire in new services - todo: more dtos - todo: add unit tests - todo: add more integration tests
34 lines
865 B
PHP
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;
|
|
}
|
|
}
|