MentalityDrillCategoryFacadeRepository.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\Repositories\Eloquent;
  3. use App\Repositories\Eloquent\BaseRepository;
  4. use App\Repositories\Contracts\MentalityDrillCategoryInterface;
  5. use App\Models\MentalityDrillCategory;
  6. use Illuminate\Database\Query\Builder;
  7. /**
  8. *
  9. * @author lilin
  10. *
  11. */
  12. class MentalityDrillCategoryFacadeRepository extends BaseRepository implements MentalityDrillCategoryInterface
  13. {
  14. public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
  15. {
  16. $result = MentalityDrillCategory::where(function(Builder $query) use($conditions){
  17. if (isset($conditions['id'])){
  18. $query->where('id', $conditions['id']);
  19. }
  20. if (isset($conditions['name'])){
  21. $query->where('name', 'like' , '%'.$conditions['name'].'%');
  22. }
  23. if (isset($conditions["isSubject"])){
  24. $query->where('is_subject', "=",0);
  25. }
  26. })->orderByRaw($sort)->paginate($limit, $fields);
  27. return $this->response($result);
  28. }
  29. public function findBy(array $conditions, array $fields){
  30. $result = MentalityDrillCategory::with(['mentalityDrill'=>function($with){
  31. $with->select(['id','pic','name']);
  32. }])->where(function($query) use($conditions){
  33. if (isset($conditions['id'])){
  34. $query->where('id', $conditions['id']);
  35. }
  36. })->first($fields);
  37. return $result ? $this->response($result) : $this->error()->dataDoesNotExist();
  38. }
  39. public function create(array $data)
  40. {
  41. $result = MentalityDrillCategory::create($data);
  42. return $result ? $this->response($result) : $this->error()->fail();
  43. }
  44. public function updateBy(array $conditions, array $data)
  45. {
  46. $result = MentalityDrillCategory::where(function($query) use($conditions){
  47. if (isset($conditions['id'])){
  48. $query->where('id', $conditions['id']);
  49. }
  50. })->update($data);
  51. return $result ? $this->response($result) : $this->error()->fail();
  52. }
  53. public function deleteBy(array $conditions)
  54. {
  55. $result = MentalityDrillCategory::where(function($query) use($conditions){
  56. if (isset($conditions['id'])){
  57. $query->where('id', $conditions['id']);
  58. }
  59. })->delete();
  60. return $result ? $this->response($result) : $this->error()->fail();
  61. }
  62. }