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