Skip to content

Commit 924b968

Browse files
committed
Update src/Http/Api/Contracts/HasModel.php, src/Http/Api/Contracts/HasRelationships.php
1 parent 30dcad6 commit 924b968

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Http/Api/Contracts/HasModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected function addTableData(array $data = [], ?Model $model = null): array
104104
$diff = array_diff(array_keys($data), $columns);
105105

106106
foreach ($diff as $key) {
107-
if ($model->hasSetMutator($key)) {
107+
if ($model->hasSetMutator($key) || $model->hasAttributeSetMutator($key)) {
108108
$columns[] = $key;
109109
}
110110
}

src/Http/Api/Contracts/HasRelationships.php

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Phpsa\LaravelApiController\Exceptions\ApiException;
66
use Phpsa\LaravelApiController\Helpers;
7+
use Illuminate\Database\Eloquent\Relations\Relation;
78

89
trait HasRelationships
910
{
@@ -24,6 +25,9 @@ protected function storeRelated($item, array $includes, array $data): void
2425

2526
foreach ($filteredRelateds as $with) {
2627
$relation = $item->$with();
28+
if($relation instanceOf Relation === false){
29+
continue;
30+
}
2731
$type = class_basename(get_class($relation));
2832
$relatedRecords = $data[Helpers::snake($with)];
2933

0 commit comments

Comments
 (0)