@@ -139,8 +139,22 @@ public static function updateById($id, array $attributes): bool
139139 $ method = strtolower (config ('microservice.models.update_method ' , 'put ' ));
140140 $ response = static ::client ()->{$ method }(static ::endpoint ().'/ ' .$ id , $ attributes );
141141
142- if (is_object ($ response ) && method_exists ($ response , 'successful ' )) {
143- return $ response ->successful ();
142+ if (is_object ($ response )) {
143+ if (method_exists ($ response , 'successful ' )) {
144+ return $ response ->successful ();
145+ }
146+
147+ if (method_exists ($ response , 'status ' )) {
148+ $ status = $ response ->status ();
149+
150+ return $ status >= 200 && $ status < 300 ;
151+ }
152+
153+ if (method_exists ($ response , 'getStatusCode ' )) {
154+ $ status = $ response ->getStatusCode ();
155+
156+ return $ status >= 200 && $ status < 300 ;
157+ }
144158 }
145159
146160 return true ;
@@ -160,6 +174,28 @@ public function update(array $attributes = [], array $options = []): bool
160174 $ method = strtolower (config ('microservice.models.update_method ' , 'put ' ));
161175 $ response = static ::client ()->{$ method }(static ::endpoint ().'/ ' .$ this ->getKey (), $ this ->attributesToArray ());
162176
177+ if (is_object ($ response )) {
178+ if (method_exists ($ response , 'successful ' ) && ! $ response ->successful ()) {
179+ return false ;
180+ }
181+
182+ if (method_exists ($ response , 'status ' )) {
183+ $ status = $ response ->status ();
184+
185+ if ($ status < 200 || $ status >= 300 ) {
186+ return false ;
187+ }
188+ }
189+
190+ if (method_exists ($ response , 'getStatusCode ' )) {
191+ $ status = $ response ->getStatusCode ();
192+
193+ if ($ status < 200 || $ status >= 300 ) {
194+ return false ;
195+ }
196+ }
197+ }
198+
163199 $ data = static ::parseResponse ($ response );
164200 if ($ fresh = static ::fromResponse ($ data )) {
165201 $ this ->fill ($ fresh ->attributesToArray ());
@@ -182,9 +218,26 @@ public function updateOrFail(array $attributes = [], array $options = []): bool
182218
183219 $ method = strtolower (config ('microservice.models.update_method ' , 'put ' ));
184220 $ response = static ::client ()->{$ method }(static ::endpoint ().'/ ' .$ this ->getKey (), $ this ->attributesToArray ());
221+ if (is_object ($ response )) {
222+ if (method_exists ($ response , 'successful ' ) && ! $ response ->successful ()) {
223+ throw new \RuntimeException ('Update failed. ' );
224+ }
185225
186- if (is_object ($ response ) && method_exists ($ response , 'successful ' ) && ! $ response ->successful ()) {
187- throw new \RuntimeException ('Update failed. ' );
226+ if (method_exists ($ response , 'status ' )) {
227+ $ status = $ response ->status ();
228+
229+ if ($ status < 200 || $ status >= 300 ) {
230+ throw new \RuntimeException ('Update failed with status ' .$ status .'. ' );
231+ }
232+ }
233+
234+ if (method_exists ($ response , 'getStatusCode ' )) {
235+ $ status = $ response ->getStatusCode ();
236+
237+ if ($ status < 200 || $ status >= 300 ) {
238+ throw new \RuntimeException ('Update failed with status ' .$ status .'. ' );
239+ }
240+ }
188241 }
189242
190243 $ data = static ::parseResponse ($ response );
@@ -208,6 +261,28 @@ public function save(array $options = []): bool
208261 $ response = static ::client ()->post (static ::endpoint (), $ this ->attributesToArray ());
209262 }
210263
264+ if (is_object ($ response )) {
265+ if (method_exists ($ response , 'successful ' ) && ! $ response ->successful ()) {
266+ return false ;
267+ }
268+
269+ if (method_exists ($ response , 'status ' )) {
270+ $ status = $ response ->status ();
271+
272+ if ($ status < 200 || $ status >= 300 ) {
273+ return false ;
274+ }
275+ }
276+
277+ if (method_exists ($ response , 'getStatusCode ' )) {
278+ $ status = $ response ->getStatusCode ();
279+
280+ if ($ status < 200 || $ status >= 300 ) {
281+ return false ;
282+ }
283+ }
284+ }
285+
211286 $ data = static ::parseResponse ($ response );
212287 if ($ fresh = static ::fromResponse ($ data )) {
213288 $ this ->fill ($ fresh ->attributesToArray ());
@@ -225,9 +300,22 @@ public function delete(): bool
225300 {
226301 $ method = strtolower (config ('microservice.models.delete_method ' , 'delete ' ));
227302 $ response = static ::client ()->{$ method }(static ::endpoint ().'/ ' .$ this ->getKey ());
303+ if (is_object ($ response )) {
304+ if (method_exists ($ response , 'successful ' )) {
305+ return $ response ->successful ();
306+ }
307+
308+ if (method_exists ($ response , 'status ' )) {
309+ $ status = $ response ->status ();
228310
229- if (is_object ($ response ) && method_exists ($ response , 'successful ' )) {
230- return $ response ->successful ();
311+ return $ status >= 200 && $ status < 300 ;
312+ }
313+
314+ if (method_exists ($ response , 'getStatusCode ' )) {
315+ $ status = $ response ->getStatusCode ();
316+
317+ return $ status >= 200 && $ status < 300 ;
318+ }
231319 }
232320
233321 return true ;
0 commit comments