123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace App\Repositories\Eloquent\Base;
- use App\Contracts\Repositories\Base\DictRepository;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\Base\Dict;
- use Prettus\Repository\Criteria\RequestCriteria;
- use Prettus\Repository\Eloquent\BaseRepository;
- class DictRepositoryEloquent extends BaseRepository implements DictRepository
- {
- protected $fieldSearchable = [
- // 'name' => 'like', Default Condition "="
- ];
- /**
- * Specify Model class name.
- *
- * @return string
- */
- public function model()
- {
- return Dict::class;
- }
- /**
- * Boot up the repository, pushing criteria.
- *
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function boot()
- {
- $this->pushCriteria(app(RequestCriteria::class));
- }
- /**
- * @return mixed
- */
- public function searchDictsByPage()
- {
- return $this->paginate(request('per_page', 15));
- }
- /**
- * @param $id
- *
- * @return mixed
- */
- public function searchDictBy($id)
- {
- return $this->find($id);
- }
- /**
- * 通过key获取配置项
- * @param $keys
- * @return mixed
- */
- public function byKeysConfigs($keys)
- {
- return $this->whereIn('code', $keys)->with(['detail' => function ($query) {
- return $query->where('status', ModelStatusEnum::OK)->orderByDesc('sort')->select(['id', 'name', 'value', 'dict_id']);
- }])->select(['id', 'name', 'code'])->get();
- }
- /**
- * 获取单个key
- * @param $key
- * @return mixed
- */
- public function byKeysConfig($key)
- {
- return $this->where('code', $key)->with(['detail' => function ($query) {
- return $query->where('status', ModelStatusEnum::OK)->orderByDesc('sort')->select(['id', 'name', 'value', 'dict_id']);
- }])->select(['id', 'name', 'code'])->first();
- }
- }
|