How to keep RESTFUL API Status Code in globally ? (Best Practice)
I want to keep all HTTP Status code in one global file with static method. What is the best practice to do this ? in laravel
Current Code
return SendResponseTrait::sendError('No data found', "Warning", 404);
Expected Code (status code declare as a class variable)
return SendResponseTrait::sendError('No data found', "Warning", self::HTTP_UNPROCESSABLE_ENTITY);
Laravel's Response class extends Symfony which already includes all the constants for status codes.
use Illuminate\Http\Response;
return Response::HTTP_UNPROCESSABLE_ENTITY
By the way, 404 would be HTTP_NOT_FOUND. HTTP_UNPROCESSABLE_ENTITY maps to 422.
Please or to participate in this conversation.