Skip to content

Commit

Permalink
Fix "Call to a member function getTranslatedAttribute() on null" (#4782)
Browse files Browse the repository at this point in the history
* Fix of BUG

Call to a member function getTranslatedAttribute() on null {"userId":4,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function getTranslatedAttribute() on null at /app/vendor/tcg/voyager/src/Http/Controllers/VoyagerBaseController.php:55

* Remove unnecessary first

* Update src/Http/Controllers/VoyagerBaseController.php

Co-Authored-By: Christoph Schweppe <info@cschweppe.de>

Co-authored-by: Christoph Schweppe <info@cschweppe.de>
  • Loading branch information
georak and emptynick committed Apr 5, 2020
1 parent dfe047e commit cd9385b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Http/Controllers/VoyagerBaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ public function index(Request $request)
$searchable = SchemaManager::describeTable(app($dataType->model_name)->getTable())->pluck('name')->toArray();
$dataRow = Voyager::model('DataRow')->whereDataTypeId($dataType->id)->get();
foreach ($searchable as $key => $value) {
$displayName = $dataRow->where('field', $value)->first()->getTranslatedAttribute('display_name');
$searchNames[$value] = $displayName ?: ucwords(str_replace('_', ' ', $value));
$field = $dataRow->where('field', $value)->first();
$displayName = ucwords(str_replace('_', ' ', $value));
if ($field !== null) {
$displayName = $field->getTranslatedAttribute('display_name');
}
$searchNames[$value] = $displayName;
}
}

Expand Down

0 comments on commit cd9385b

Please sign in to comment.