Skip to content

Commit

Permalink
Improve resource getter calling
Browse files Browse the repository at this point in the history
  • Loading branch information
akalongman committed Jan 21, 2021
1 parent d34d71e commit c9f8f6c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Lodash/Http/Resources/TransformsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ trait TransformsData
* Fields transform mapping.
* In array key should be a column name from database,
* value can be just name (if getter exists for that name, or array [fieldName => getterMethod]).
* If getterMethod is defined in the resource class, it will be called, otherwise, model's method will be used.
* If static getterMethod is defined in the resource class, it will be called and as a first argument will be passed TransformableContract $model,
* other arguments will be rsolved via dependency injection.
* Otherwise, model's method will be used.
*/
protected static array $transformMapping = [];

Expand Down Expand Up @@ -74,7 +76,7 @@ private static function parseKeyValue(string $internalField, $transformValue, Tr
$key = key($transformValue);
$method = $transformValue[$key];
if (method_exists(static::class, $method)) { // Check if getter exists in the resource class
$value = app()->call([static::class, $method]);
$value = app()->call([static::class, $method], ['model' => $model]);
} elseif (method_exists($model, $method)) { // Check if getter exists in the model class
$value = $model->$method();
} else {
Expand Down

0 comments on commit c9f8f6c

Please sign in to comment.