Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Apply criteria in query repository
- *
- * @param string $model
- * @param RepositoryInterface $repository
- *
- * @return mixed
- */
- public function apply($model, RepositoryInterface $repository)
- {
- $this->oldsql = $model;
- // 用上一次的條件(僅限定 where) 作 關聯子查詢
- $model = $model->whereNotExists(function ($query) {
- $oldquery = $this->oldsql->getQuery();
- $query->from($oldquery->from);
- foreach ($oldquery->wheres as $where) {
- $query->whereRaw($where['sql']);
- }
- $query->whereRaw('id = parent_id');
- $query->mergeBindings($oldquery);
- });
- // dd($model->toSql());
- return $model;
- }
Add Comment
Please, Sign In to add comment