1414namespace App \Base \Traits ;
1515
1616use App \Base \Abstracts \Models \BaseCollection ;
17+ use App \Base \Abstracts \Models \BaseModel ;
1718use App \Base \Abstracts \Models \ModelWithLocationCollection ;
1819use App \Base \GraphQl \GraphQLExport ;
1920
@@ -42,6 +43,10 @@ trait WithLatLngTrait
4243 #[GraphQLExport]
4344 public function getLatitude (): float
4445 {
46+ if ($ this instanceof BaseModel && !$ this ->latitude ) {
47+ $ this ->latitude = floatval ($ this ->getData ('latitude ' ) ?? 0.0 );
48+ }
49+
4550 return $ this ->latitude ;
4651 }
4752
@@ -53,6 +58,10 @@ public function getLatitude(): float
5358 #[GraphQLExport]
5459 public function getLongitude (): float
5560 {
61+ if ($ this instanceof BaseModel && !$ this ->longitude ) {
62+ $ this ->longitude = floatval ($ this ->getData ('longitude ' ) ?? 0.0 );
63+ }
64+
5665 return $ this ->longitude ;
5766 }
5867
@@ -88,4 +97,36 @@ public function nearBy(float $radius) : ModelWithLocationCollection|BaseCollecti
8897
8998 return $ collection ;
9099 }
100+
101+ /**
102+ * sets latitude
103+ *
104+ * @param float $latitude
105+ * @return self
106+ */
107+ public function setLatitude (float $ latitude ): self
108+ {
109+ $ this ->latitude = $ latitude ;
110+ if ($ this instanceof BaseModel) {
111+ $ this ->setData (['latitude ' => $ latitude ]);
112+ }
113+
114+ return $ this ;
115+ }
116+
117+ /**
118+ * sets longitude
119+ *
120+ * @param float $longitude
121+ * @return self
122+ */
123+ public function setLongitude (float $ longitude ): self
124+ {
125+ $ this ->longitude = $ longitude ;
126+ if ($ this instanceof BaseModel) {
127+ $ this ->setData (['longitude ' => $ longitude ]);
128+ }
129+
130+ return $ this ;
131+ }
91132}
0 commit comments