jikan-rest/app/JikanApiModel.php
pushrbx 0211fc4128 multiple fixes
- updated api docs
- fixed top reviews endpoint
- fixed reviews parsing
- added "contextual" boolean query string parameters, so params without value can be interpreted as "boolean". E.g. ?sfw or ?kid in the url would add "true" value to their corresponding field in the DTO
- fixed typesense issues
2023-05-21 11:18:02 +01:00

29 lines
909 B
PHP

<?php
namespace App;
use App\Filters\FilterQueryString;
use Illuminate\Support\Collection;
use Jenssegers\Mongodb\Eloquent\Builder;
class JikanApiModel extends \Jenssegers\Mongodb\Eloquent\Model
{
use FilterQueryString;
/**
* The list of parameters which can be used to filter the result-set from the database.
* The available field names and "order_by" is allowed as values. If "order_by" is specified then the field name
* from the "order_by" query string parameter will be used to sort the results.
* @var string[]
*/
protected array $filters = [];
/** @noinspection PhpUnused */
public function scopeRandom(Builder $query, int $numberOfRandomItems = 1): Collection
{
return $query->raw(fn(\Jenssegers\Mongodb\Collection $collection) => $collection->aggregate([
['$sample' => ['size' => $numberOfRandomItems]]
]));
}
}