UserCriteria.php 648 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Repositories\Criteria;
  11. use Illuminate\Database\Eloquent\Builder;
  12. class UserCriteria extends Criteria
  13. {
  14. protected function condition(Builder $query): void
  15. {
  16. if ($name = $this->request->get('name')) {
  17. $query->where('name', '=', $name);
  18. }
  19. if ($email = $this->request->get('email')) {
  20. $query->where('email', 'like', "%$email%");
  21. }
  22. }
  23. }