26 lines
503 B
PHP
26 lines
503 B
PHP
<?php
|
|
|
|
namespace App\Lib;
|
|
|
|
use Spatie\LaravelData\Data;
|
|
|
|
class Sorting extends Data
|
|
{
|
|
public static function by(string $by): self
|
|
{
|
|
return static::factory()->withoutMagicalCreation()->from(['by' => $by]);
|
|
}
|
|
|
|
public function __construct(public string $by, public bool $direction = false)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public function toMeilisearch(): array
|
|
{
|
|
return [$this->by . ':' . ($this->direction ? 'desc' : 'asc')];
|
|
}
|
|
}
|