Check this link https://laravel.com/docs/7.x/http-tests#customizing-request-headers
Example
$ response = $ this->withHeaders(['Authorization'=>'Bearer '.$token)->post ('api / store', $ data);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I should test some bees with jetstream / Sanctum
to test bees with Insomnia just send the request as follows:
GET: http://laravel.test/api
Content-Type:application/json
Accept:application/json
Authorization:Bearer 37b3mWZ9BHc....LRZwbTnYBKtcQss
but if I have to test it from code? obviously with active middleware !
without token before i tested the api as follows from code
$ data = [
"a" => "3",
"b" => "2",
"c" => ["a" => "yes", "b" => "no"],
];
$ response = $ this->post ('api/store', $ data);
with bearer token how do I send the $data request?
Check this link https://laravel.com/docs/7.x/http-tests#customizing-request-headers
Example
$ response = $ this->withHeaders(['Authorization'=>'Bearer '.$token)->post ('api / store', $ data);
Please or to participate in this conversation.