Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix additional attributes when using local scope #4875

Merged
merged 3 commits into from
May 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Http/Controllers/VoyagerBaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,8 @@ public function relation(Request $request)
$options = $row->details;
$model = app($options->model);
$skip = $on_page * ($page - 1);

$additional_attributes = $model->additional_attributes ?? [];

// Apply local scope if it is defined in the relationship-options
if (isset($options->scope) && $options->scope != '' && method_exists($model, 'scope'.ucfirst($options->scope))) {
Expand All @@ -868,7 +870,7 @@ public function relation(Request $request)
// If search query, use LIKE to filter results depending on field label
if ($search) {
// If we are using additional_attribute as label
if (in_array($options->label, $model->additional_attributes ?? [])) {
MrCrayon marked this conversation as resolved.
Show resolved Hide resolved
if (in_array($options->label, $additional_attributes)) {
$relationshipOptions = $model->all();
$relationshipOptions = $relationshipOptions->filter(function ($model) use ($search, $options) {
return stripos($model->{$options->label}, $search) !== false;
Expand Down