Guest User

Untitled

a guest
Jul 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. /**
  2. * Apply criteria in query repository
  3. *
  4. * @param string $model
  5. * @param RepositoryInterface $repository
  6. *
  7. * @return mixed
  8. */
  9. public function apply($model, RepositoryInterface $repository)
  10. {
  11. $this->oldsql = $model;
  12.  
  13. // 用上一次的條件(僅限定 where) 作 關聯子查詢
  14. $model = $model->whereNotExists(function ($query) {
  15. $oldquery = $this->oldsql->getQuery();
  16. $query->from($oldquery->from);
  17. foreach ($oldquery->wheres as $where) {
  18. $query->whereRaw($where['sql']);
  19. }
  20. $query->whereRaw('id = parent_id');
  21. $query->mergeBindings($oldquery);
  22. });
  23.  
  24. // dd($model->toSql());
  25. return $model;
  26. }
Add Comment
Please, Sign In to add comment