I don't know if this forum has ever been active, but the support I received as a newcomer is equal to zero.
Apr 7, 2025
2
Level 1
[Closed] Laravel ^12.0 seems to break ResponseFactory macros
Good day. I migrated from Laravel 11 to Laravel 12 using the official guide, and I have a strange behaviour with Http macros. I've defined them in the AppServiceProvider boot's method:
$resultModel = function (string $status, string $message, int $code, mixed $data = null): array {
$model = array();
$model['status'] = $status;
$model['message'] = $message;
$model['code'] = $code;
if (!empty($data)) {
$model['result'] = $data;
}
return $model;
};
// Success HTTP Response
Response::macro('success', function (mixed $data = null, int $code = 200) use ($resultModel) {
// render info
$code = $code == 0 ? 200 : $code;
$model = $resultModel(
'OK',
'success',
$code,
$data,
);
return Response::make($model, $code);
});
// Fail HTTP Response
Response::macro('fail', function (string $message, int $code = 400) use ($resultModel) {
// render info
$code = $code == 0 ? 500 : $code;
$model = $resultModel(
'KO',
$message,
$code,
);
return Response::make($model, $code);
});
And they were working fine. As soon as I updated Laravel, using something like:
return response()->fail();
makes Intelephense saying:
Undefined method 'fail' (P1013)
Could you please help me?
Thank you in advance.
Kind regards.
Level 1
Please or to participate in this conversation.