51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin;
|
|
|
|
use Slowlyo\OwlAdmin\Services\AdminService;
|
|
|
|
/**
|
|
* @method Region getModel()
|
|
* @method Region|\Illuminate\Database\Query\Builder query()
|
|
*/
|
|
class BaseService extends AdminService
|
|
{
|
|
protected array $withRelationships = [];
|
|
|
|
protected string $modelFilterName = '';
|
|
|
|
public function getTree()
|
|
{
|
|
$list = $this->query()->orderByDesc('sort')->get();
|
|
$minNum = $list->min('parent_id');
|
|
return array2tree($list->toArray(), $minNum);
|
|
}
|
|
|
|
public function getModelFilter()
|
|
{
|
|
return $this->modelFilterName;
|
|
}
|
|
|
|
public function listQuery()
|
|
{
|
|
$model = $this->getModel();
|
|
$filter = $this->getModelFilter();
|
|
|
|
$query = $this->query();
|
|
if($this->withRelationships){
|
|
$query->with($this->withRelationships);
|
|
}
|
|
|
|
if ($filter) {
|
|
$query->filter(request()->input(), $filter);
|
|
}
|
|
|
|
return $query->orderByDesc($model->getUpdatedAtColumn() ?? $model->getKeyName());
|
|
}
|
|
|
|
public function getDetail($id)
|
|
{
|
|
return $this->query()->with($this->withRelationships)->find($id);
|
|
}
|
|
}
|