Complete BLoC with Clean Architecture (group chat) Discount !! E-commerce App With Backend Source Code Video and Voice Chatting App Firebase Chatting App Source Code Complete Gym App BLoC State Management Source Code Complete Study App Buy Ticket Booking App Source Code Buy Travel App With Backend Source Code Complete Chat App Udemy Course Special Offer Discount !! Online Learning Course App (BLoC) Online Learning Course App (Riverpod) Online Learning Course App (Getx) Discount !! Shopping App (Provider) Cool Flutter Game Flutter Nodejs Chat App Flutter Nodejs Api And Firebase Chat App Riverpod Task Management App
When you build Laravel api, you may encounter below error
"error":
"Symfony\ \Component\\HttpFoundation\\(Response: :setStatusCode
(): Argument #1 ($code) must be of type int, string given, called
in.....
There could be many reasons why you encounter this. But from the first glance, we don't know what's this error about. To know this error, we need to wrap our api around the below try catch clause
try{
.......................................
}catch (\Throwable $th) {
return response()->json([
'status' => false,
'message' => $th->getMessage()
], 500);
}
The magic happens inside catch clause
. You need to use Throwable class and return $th->getMessage(), to know the exact error.
But to use you need to have special settings in Exception.php class in Laravel. Check out from the link. Once you have the correct setup, you may run your api test on postman. And you would be able to catch the exact error. In our case it was the database error. I forgot to send value for database field that has non-nullable property.
So I have a non-nullable field which needs value during data insert.
For Laravel non-nullable field, you must assign value if there's no default value assigned for them. So I assigned value during data insert and value got resolved.