123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace app\Repositories\Eloquent;
- use App\Repositories\Eloquent\BaseRepository;
- use App\Repositories\Contracts\MentalityDrillCategoryInterface;
- use App\Models\MentalityDrillCategory;
- use Illuminate\Database\Query\Builder;
- /**
- *
- * @author lilin
- *
- */
- class MentalityDrillCategoryFacadeRepository extends BaseRepository implements MentalityDrillCategoryInterface
- {
- public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
- {
- $result = MentalityDrillCategory::where(function(Builder $query) use($conditions){
- if (isset($conditions['id'])){
- $query->where('id', $conditions['id']);
- }
- if (isset($conditions['name'])){
- $query->where('name', 'like' , '%'.$conditions['name'].'%');
- }
- if (isset($conditions["isSubject"])){
- $query->where('is_subject', "=",0);
- }
- })->orderByRaw($sort)->paginate($limit, $fields);
- return $this->response($result);
- }
- public function findBy(array $conditions, array $fields){
- $result = MentalityDrillCategory::with(['mentalityDrill'=>function($with){
- $with->select(['id','pic','name']);
- }])->where(function($query) use($conditions){
- if (isset($conditions['id'])){
- $query->where('id', $conditions['id']);
- }
- })->first($fields);
- return $result ? $this->response($result) : $this->error()->dataDoesNotExist();
- }
- public function create(array $data)
- {
- $result = MentalityDrillCategory::create($data);
- return $result ? $this->response($result) : $this->error()->fail();
- }
- public function updateBy(array $conditions, array $data)
- {
- $result = MentalityDrillCategory::where(function($query) use($conditions){
- if (isset($conditions['id'])){
- $query->where('id', $conditions['id']);
- }
- })->update($data);
- return $result ? $this->response($result) : $this->error()->fail();
- }
- public function deleteBy(array $conditions)
- {
- $result = MentalityDrillCategory::where(function($query) use($conditions){
- if (isset($conditions['id'])){
- $query->where('id', $conditions['id']);
- }
- })->delete();
- return $result ? $this->response($result) : $this->error()->fail();
- }
- }
|