See https://laravel.com/docs/11.x/sanctum#issuing-api-tokens
Or use a controller.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Long story short, does anyone know how to embed API requests into blade without having to included the bearer token (personal access token) in the page source? I'm guessing it's not best practice to embed a token in the page source, even for first party.
Currently the only way I can make API requests with auth work is by using an extension to alpine.js that lets me add attributes to my links in blade files like:
@click="$post({route: '/api/my-route', headers: {Authorization: 'Bearer {{ config('app.api_token') }}'} })"
But this ends up rendering in the page source of course (and if it didn't, it would be in some javascript source somewhere). Is there a better alternative for embedding links like this?
Please or to participate in this conversation.