Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gathuku's avatar

Internal Api Requests

hello, am consuming an internal API within the same laravel application.

Here is how am sending the request

    $request = Request::create('/api/v1/login', 'POST',[
      'name'=>Input::get('email'),
      'password'=>Input::get('password')
      ]);

    $response = Route::dispatch($request);

form_params are working well Someone help how i can pass headers with authorization bearer token.

0 likes
5 replies
jrdavidson's avatar

Well, I don't believe there is a dispatch method on the Route class or a create method on the Request class.. Where did you see these methods?

jrdavidson's avatar

Ah okay. Take a look at the other responses on that post. More people are saying to use app()->handle() rather than Route::dispatch().

gathuku's avatar
gathuku
OP
Best Answer
Level 1

@XTREMER360 - Here is how you can add it.

$request->headers->set('Authorization','Bearer '.token);

Please or to participate in this conversation.