Prido's avatar
Level 2

Laravel response()

I am trying to get the status code that i set in laravel api response. Returning response Edited

return response()-json(["status" =>"success"], 201);

Now in my angular app

this.http.post('http://example').subscribe( (data) => {
if(data.code === 201){
}
}) ;

How can i get the status or am i missing something?

0 likes
3 replies
tykus's avatar

@prido as I mentioned last night (and it disappeared because the other contributor deleted their reply); you need to tell Angular's HTTP client that you want more than just the response body by using the observe option on the GET request:

this.http.post('http://example', {observe: 'response'})
	.subscribe( (data) => {
		if(data.status === 201){
			// ...
		}
	}) ;

https://angular.io/guide/http#requesting-data-from-a-server

Please or to participate in this conversation.