ArticleRepositoryEloquent.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Repositories;
  3. use Prettus\Repository\Eloquent\BaseRepository;
  4. use Prettus\Repository\Criteria\RequestCriteria;
  5. use App\Repositories\ArticleRepository;
  6. use App\Models\Article;
  7. /**
  8. * Class ArticleRepositoryEloquent
  9. * @package namespace App\Repositories;
  10. */
  11. class ArticleRepositoryEloquent extends BaseRepository implements ArticleRepository
  12. {
  13. /**
  14. * Specify Model class name
  15. *
  16. * @return string
  17. */
  18. public function model()
  19. {
  20. return Article::class;
  21. }
  22. /**
  23. * Boot up the repository, pushing criteria
  24. */
  25. public function boot()
  26. {
  27. $this->pushCriteria(app(RequestCriteria::class));
  28. }
  29. /**
  30. * 根据关键字搜索文章
  31. *
  32. * @param $keyword
  33. * @return mixed
  34. */
  35. public function searchKeywordArticle($keyword)
  36. {
  37. $search = "%".$keyword."%";
  38. $this->applyConditions([['title', 'like', $search]]);
  39. return $this->paginate(15, ['id','title','desc','user_id','cate_id','read_count','created_at']);
  40. }
  41. /**
  42. * 搜索文章
  43. *
  44. * @param array $where
  45. * @return mixed
  46. */
  47. public function backendSearchArticle(array $where)
  48. {
  49. if (count($where) > 0) {
  50. $this->applyConditions($where);
  51. }
  52. return $this->orderBy('id', 'desc')->paginate(15);
  53. }
  54. }