How to replace to Illuminate\Http\Client\Response to custom Response #45908
Unanswered
Haythamasalama
asked this question in
Q&A
Replies: 1 comment
-
To replace the
namespace App\Http\Responses;
use Illuminate\Http\Response;
class CustomResponse extends Response
{
// Add your custom methods and properties here
}
use Illuminate\Support\ServiceProvider;
use App\Http\Responses\CustomResponse;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Response::macro('custom', function ($content = '', $status = 200, array $headers = []) {
return new CustomResponse($content, $status, $headers);
});
}
}
return response()->custom($content, $status, $headers); This will return an instance of your custom response class, which you can use to return customized responses in your application. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I wanna make a custom response for response in
HTTP Client
to overwrite thethrow()
method. but how to replace in all HTTP classes that are usedIlluminate\Http\Client\Response
toBaseResponse
in clean way ?I tried to use the
alias()
andbind()
method inAppServiceProvider
but didn't works.Beta Was this translation helpful? Give feedback.
All reactions