8000 [Feature] Allow dot notation for soft delete field name (#361) · CodingSeo/laravel-json-api@0a74dad · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a74dad

Browse files
JeanLucEsserlindyhopchris
authored andcommitted
[Feature] Allow dot notation for soft delete field name (cloudcreativity#361)
If the soft delete field is a nested attribute (e.g. `status.deleted-at`), use Laravel array helpers to use the attribute.
1 parent 4520cf6 commit 0a74dad

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Eloquent/Concerns/SoftDeletesModels.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use CloudCreativity\LaravelJsonApi\Utils\Str;
2222
use Illuminate\Database\Eloquent\Model;
2323
use Illuminate\Database\Schema\Builder;
24+
use Illuminate\Support\Arr;
2425
use Illuminate\Support\Collection;
2526
use Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
2627

@@ -61,13 +62,14 @@ protected function findQuery($resourceId)
6162
protected function fillAttributes($record, Collection $attributes)
6263
{
6364
$field = $this->getSoftDeleteField($record);
65+
$attributesArr = $attributes->toArray();
6466

65-
if ($attributes->has($field)) {
66-
$this->fillSoftDelete($record, $field, $attributes->get($field));
67+
if (Arr::has($attributesArr, $field)) {
68+
$this->fillSoftDelete($record, $field, Arr::get($attributesArr, $field));
6769
}
6870

6971
$record->fill(
70-
$this->deserializeAttributes($attributes->forget($field), $record)
72+
$this->deserializeAttributes(Arr::except($attributesArr, $field), $record)
7173
);
7274
}
7375

0 commit comments

Comments
 (0)
0