Add a Voice AI Agent to a Laravel App
Add the AnveVoice voice agent to a Laravel 12 or 13 app by placing one script tag in your Blade layout, using a stack, and clearing the view cache.
How to add AnveVoice to a Laravel application
In Laravel the page shell lives in a Blade layout. Paste the AnveVoice tag into that layout, either at the end of the body or through a @stack so individual views can add it. Clear compiled views, and the voice button shows up on every route that uses the layout. Steps checked against the official documentation on 2026-10-14.
At a glance
- Where the code goes: resources/views/components/layout.blade.php or resources/views/layouts/app.blade.php, just before </body>
- Coding needed: One line in a Blade file; no package, no Vite build step
- Plan limits: None from Laravel; applies on your own server, Forge, Vapor or any host
- Time: About 3 minutes
Which layout style does your app use?
Laravel's Blade documentation describes two ways to build a shared page shell, and the tag goes in a different file depending on which one your project uses. Newer applications and starter kits typically define a layout component, a file such as resources/views/components/layout.blade.php that echoes {{ $slot }} and is applied with an <x-layout> tag. Older or upgraded projects often use template inheritance: a parent such as resources/views/layouts/app.blade.php with @yield('content'), extended by views with @extends. Open a page you want the voice agent on and look at its first line to see which one applies. Either way, you will edit the parent layout once and every child view inherits the change. If your app has more than one layout (for example a marketing layout and a dashboard layout) add the tag to each layout where you want the button. Also note that Laravel 13 is now the current documentation release; the Blade layout and stack features described here are the same in versions 12 and 13.
- 1. Get your install tag — Create a bot for your site in the AnveVoice dashboard at app.anvevoice.app and copy the embed ID. Swap it in for YOUR_EMBED_ID. Because the URL contains no Blade braces, it needs no escaping or @verbatim wrapper. Code: <script src="https://anvevoice.app/embed.js?embedId=YOUR_EMBED_ID" async></script>
Method 1: put the tag directly in the layout
- 1. Open the layout file — Edit the parent layout identified above: resources/views/components/layout.blade.php for the component style or resources/views/layouts/app.blade.php for inheritance.
- 2. Insert the tag above the closing body tag — Place the script after your page content so it never delays rendering. In a component layout it looks like this: Code: <body> {{ $slot }} <script src="https://anvevoice.app/embed.js?embedId=YOUR_EMBED_ID" async></script> </body>
- 3. Reload — Blade recompiles a view when its file changes, so a browser refresh in local development is normally enough.
Method 2: use a Blade stack
Blade stacks let a child view push content into a named spot in the layout. The documentation describes @push('scripts') in a view and @stack('scripts') in the layout, and notes that @pushOnce prevents duplicates when the same snippet might be pushed from several templates. Use this method when only some pages should carry the voice agent, for example your pricing page and not your admin screens.
- 1. Add a stack to the layout — In the layout, add a stack just before the closing body tag. Code: @stack('scripts') </body>
- 2. Push the tag from selected views — In each view that should show the button, push the tag. Use @pushOnce with a unique ID to guard against double inclusion. Code: @pushOnce('scripts', 'anvevoice') <script src="https://anvevoice.app/embed.js?embedId=YOUR_EMBED_ID" async></script> @endPushOnce
Production notes specific to Laravel
- Compiled views: in production, run php artisan view:clear (or redeploy with your usual optimize step) so the cached Blade files are rebuilt with the new tag.
- Vite is not involved. The Vite documentation covers bundling your own assets through @vite; a third-party script from another domain does not belong in resources/js, and bundling it would stop it updating independently.
- Content Security Policy: if you send a CSP header, add https://anvevoice.app to the script-src directive. If you use Laravel's Vite nonce support (Vite::useCspNonce in middleware), the nonce applies to Vite-generated tags; for a hand-written tag add the host to script-src rather than relying on the nonce.
- Inertia, Livewire and SPA-style navigation: the layout is rendered once on the first load, so the tag is not re-executed on client-side navigations, and that is what you want. The script also ignores a second copy on the same page.
- Multiple environments: wrap the tag in @production ... @endproduction if you do not want the voice agent on local or staging copies, or use a different embed ID per environment from config.
Check that it works
- 1. View source — Open a page in a private window, view the page source and search for embed.js; it should appear once, before the closing body tag.
- 2. Try the button — Click the round microphone button at the bottom-right, allow the microphone (the site must be HTTPS or localhost) and ask a question.
Common problems
- Tag missing on some routes: those views use a different layout. Add the tag there or switch them to the shared layout.
- Button shows twice: the tag is both in the layout and pushed from a view. Keep one, or use @pushOnce.
- Old HTML after deploy: view cache or full-page cache (CDN, Nginx fastcgi cache) is still serving the previous page. Clear it.
- Blocked by CSP: the browser console shows a script-src violation. Allow https://anvevoice.app in your policy.
Sources
- Laravel 13.x Blade Templates (layouts, stacks, @pushOnce) (https://laravel.com/docs/13.x/blade) — checked 2026-10-14
- Laravel 12.x Blade Templates (https://laravel.com/docs/12.x/blade) — checked 2026-10-14
- Laravel 12.x Asset Bundling (Vite) and CSP nonce (https://laravel.com/docs/12.x/vite) — checked 2026-10-14
Related
- How to add AnveVoice to a Ruby on Rails app
- How to add AnveVoice to a Django project
- How to add AnveVoice to a Flask application
- How to add AnveVoice to a WordPress site
Try AnveVoice on your site
Free plan: $0, 50,000 tokens a month, no card. Get your embed ID in the dashboard, then paste one tag.