Skip to content

Commit

Permalink
fix: null reference on gift photo upload (#5547)
Browse files Browse the repository at this point in the history
Attempting to connect a photo to a gift, either an already existing one
or a freshly uploaded one, the AJAX call would return a 500 server
error. The error states of a `Attempt to read property "id" on null` in
`app\Http\Resources\Gift/Gift` line 24.

This is causes by attempting to use a void result of
`AssociatePhotoToGift` service in `ApiGiftController::associate()`
method.

Fixed by returning the actual `$gift` variable worked on, similar to the
related services.

This does fix the *stacktrace* in #5516, but not the issue itself. The
issue there is likely unrelated to the stacktrace.

Fixes #5397
  • Loading branch information
particleflux authored Oct 8, 2021
1 parent a669e98 commit 2c33e0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/Services/Contact/Gift/AssociatePhotoToGift.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ public function execute(array $data)
$gift->contact->throwInactive();

$gift->photos()->syncWithoutDetaching([$photo->id]);

return $gift;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ public function it_associates_a_photo_to_a_gift()
'account_id' => $gift->account_id,
]);

app(AssociatePhotoToGift::class)->execute([
$giftUpdated = app(AssociatePhotoToGift::class)->execute([
'account_id' => $gift->account_id,
'gift_id' => $gift->id,
'photo_id' => $photo->id,
]);

$this->assertInstanceOf(Gift::class, $giftUpdated);
$this->assertEquals($gift->id, $giftUpdated->id);

$this->assertDatabaseHas('gift_photo', [
'gift_id' => $gift->id,
'photo_id' => $photo->id,
Expand Down

0 comments on commit 2c33e0b

Please sign in to comment.