Created
March 10, 2020 14:54
-
-
Save fridzema/eaf96d9d1e05995700d86a1bc5191b67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function generateRelationsQuery($request, $db_query, $model, $filter_relations) | |
{ | |
$filter_appends = []; | |
foreach ($filter_relations as $key => $value) { | |
if (!isset($value['custom_query'])) { | |
if ($request->has('filter-remote-' . strtolower($key))) { | |
$select_value = $request->input('filter-remote-' . strtolower($key)); | |
if (!empty($select_value)) { | |
$filter_appends['filter-remote-' . strtolower($key)] = $select_value; | |
if (false != strpos($value['field'], '.')) { | |
$splitted_filter_values = explode(',', $select_value); | |
$values = explode('.', $value['field']); | |
$db_query->whereHas($values[0], function ($db_query) use ($model, $values, $splitted_filter_values) { | |
$db_query->where(function ($db_query) use ($model, $values, $splitted_filter_values) { | |
$db_query->whereIntegerInRaw($values[1], $splitted_filter_values); | |
}); | |
}); | |
} else { | |
$db_query->whereIntegerInRaw($model . '.' . $value['field'], explode(',', $select_value)); | |
} | |
} | |
} | |
} | |
} | |
return $filter_appends; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment