Working in Laravel 5.4
After deleting an image (in my ImageRepository) I send a Json response back to my Controller (where I called the ImageRepository). Now I simply want to check what status code I am getting back to further build on that.
return Response::json([
'error' => false,
'code' => 200,
'message' => 'Image was deleted!'
], 200);
When I receive this response in my Controller and I dd();
it I see this:
JsonResponse {#461 ▼
#data: "{"error":false,"code":200,"message":"Image was deleted!"}"
#callback: null
#encodingOptions: 0
+headers: ResponseHeaderBag {#459 ▶}
#content: "{"error":false,"code":200,"message":"Image was deleted!"}"
#version: "1.0"
#statusCode: 200
#statusText: "OK"
#charset: null
+original: array:3 [▶]
+exception: null
}
I only need to extract the statusCode so that I can send the correct notification to the user (image deleted, image not found, imaage ...)
Can't believe I cannot find a solution for this anywhere.
Thanks
Basic Response Laravel provides several different ways to return response. Response can be sent either from route or from controller. The basic response that can be sent is simple string as shown in the below sample code. This string will be automatically converted to appropriate HTTP response.
It stands for JavaScript Object Notation and it provides a great way to share data between languages and applications. Douglas I'm sure is proud of his baby, and we can thank him for declaring himself a standards body and bringing JSON into existence. Let's learn a little more about JSON in Laravel!
https://laravel.com/api/5.8/Illuminate/Http/RedirectResponse.html
$response->status();
Get the status code for the response.
It will return the status code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With