Level 10
Maybe this works:
$response = (new $controllerName)->methodName();
// get header data
$response->headers->all();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
To call a controller I use a CURL request like this:
curl -kX POST https://site/method -H 'Authorization: Bearer ACCESS_TOKEN\
Content-Type:application/json' -d '
{
"param1":"value 1",
"param2":"value 2",
"param3":"value 3"
}'
The route calls UserController@method.
How can I do the same from Laravel code (internal request, not sending CURL)?
I've found an advice to use something like this
$controller = app()->make($controllerName);
$response = app()->call([$controller, 'method'], []);
echo $response;
where the last [] should contain some parameters. But if this is the way, I cannot figure out how the array should look in my case.
Well, here is my answer to my question https://stackoverflow.com/questions/44982067/call-laravel-controller-from-code-and-pass-http-headers-to-it/44988932#44988932
Please or to participate in this conversation.