DepartmentRepositoryEloquent.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Repositories\Eloquent\Base;
  3. use App\Contracts\Repositories\Base\DepartmentRepository;
  4. use App\Repositories\Models\Base\Department;
  5. use Prettus\Repository\Criteria\RequestCriteria;
  6. use Prettus\Repository\Eloquent\BaseRepository;
  7. class DepartmentRepositoryEloquent extends BaseRepository implements DepartmentRepository
  8. {
  9. protected $fieldSearchable = [
  10. // 'name' => 'like', Default Condition "="
  11. ];
  12. /**
  13. * Specify Model class name.
  14. *
  15. * @return string
  16. */
  17. public function model()
  18. {
  19. return Department::class;
  20. }
  21. /**
  22. * Boot up the repository, pushing criteria.
  23. *
  24. * @throws \Prettus\Repository\Exceptions\RepositoryException
  25. */
  26. public function boot()
  27. {
  28. $this->pushCriteria(app(RequestCriteria::class));
  29. }
  30. /**
  31. * @return mixed
  32. */
  33. public function searchDepartmentsByPage()
  34. {
  35. return $this->paginate(request('per_page', 15));
  36. }
  37. public function searchDepartments()
  38. {
  39. return $this->all();
  40. }
  41. /**
  42. * @param $id
  43. *
  44. * @return mixed
  45. */
  46. public function searchDepartmentBy($id)
  47. {
  48. return $this->find($id);
  49. }
  50. public function tree($where)
  51. {
  52. return toTree($this->all());
  53. }
  54. }