Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
Made quick below_model filter
Browse files Browse the repository at this point in the history
  • Loading branch information
hcaz committed Jul 19, 2021
1 parent 7180aed commit dc1c09f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/FromRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,40 @@ public function scopeFromRequest(Builder $query, Request $request, $namespace =
$namespace = $this->requestNameSpace;
}

/// This will only work on resources for now
///
/// This whole thing needs to be moved into a sub query just for the orWhereHas() stuff, I dont like that it has the foreach $namespace.where within the loop
foreach ($request->input("$namespace.below", []) as $key => $value) {
if (in_array($key, $this->relationships)) {
$whereHas = $key;
$depth = 3;
for ($d = 0; $depth >= $d; $d++) {
if($d == $depth) {
$query = $query->whereHas(
$whereHas,
function (Builder $sub_query) use ($request, $namespace, $key) {
$sub_query->fromRequest($request, "$namespace.below.$key");
}
);
} else {
$query = $query->orWhereHas(
$whereHas,
function (Builder $sub_query) use ($request, $namespace, $key) {
$sub_query->fromRequest($request, "$namespace.below.$key");
}
);

foreach ($request->input("$namespace.where", []) as $key2 => $value2) {
if ($this->isValidField($key2)) {
$query = $query->where($key2, $value2);
}
}
}
$whereHas = $whereHas . '.' . $key;
}
}
}

// String filters
foreach ($request->input("$namespace.where", []) as $key => $value) {
if ($this->isValidField($key)) {
Expand Down

0 comments on commit dc1c09f

Please sign in to comment.