Files
nexusphp/app/Repositories/BaseRepository.php

19 lines
393 B
PHP
Raw Normal View History

2021-04-17 19:01:33 +08:00
<?php
namespace App\Repositories;
use Illuminate\Support\Str;
class BaseRepository
{
protected function getSortFieldAndType(array $params)
{
$field = $params['sort_field'] ?? 'id';
$type = 'desc';
if (!empty($params['sort_type']) && Str::startsWith($params['sort_type'], 'asc')) {
$type = 'asc';
}
return [$field, $type];
}
}