Skip to content

Commit

Permalink
fix: optional catch for x/y on marker
Browse files Browse the repository at this point in the history
  • Loading branch information
mwargan committed Dec 29, 2023
1 parent f067c3d commit 5a6ad73
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/Models/Marker.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,20 @@ public function user()
return $this->belongsTo(\App\Models\User::class);
}

/**
* Get the X attribute.
*
* Note, while there shouldn't be a case where there is no location for a marker, it could happen due to the architecture of the marker->location relationship - this is why its wrapped in an optional
*
*/
public function getXAttribute()
{
return $this->location->longitude;
return optional($this->location)->longitude;
}

public function getYAttribute()
{
return $this->location->latitude;
return optional($this->location)->latitude;
}

public function getLocationAttribute()
Expand Down

0 comments on commit 5a6ad73

Please sign in to comment.