genealabs/laravel-tawk
Adds the Tawk.to live chat widget to your Laravel app with minimal setup. Configure your Tawk property ID and settings via config/env, then include the provided view/component to load the script on your pages.
composer require mikebronner/laravel-tawk
php artisan vendor:publish --provider="MikeBronner\LaravelTawk\TawkServiceProvider"
.env: Add your Tawk.to site ID:
TAWK_SITE_ID=your_site_id_here
app/Providers/AppServiceProvider.php:
use MikeBronner\LaravelTawk\Facades\Tawk;
public function boot()
{
Tawk::init();
}
The widget will now appear on all pages. For dynamic control, use:
Tawk::init(['enabled' => false]); // Disable on specific pages
// app/Http/Middleware/EnableTawk.php
public function handle($request, Closure $next)
{
if (auth()->check()) {
Tawk::init(['enabled' => false]);
}
return $next($request);
}
// resources/js/app.js
window.addEventListener('tawk:chatStart', () => {
console.log('Chat started! Screenshot and console logs will auto-capture.');
});
Tawk::init([
'properties' => [
'user_id' => auth()->id(),
'user_email' => auth()->user()->email,
],
]);
Route::get('/support', function () {
Tawk::init(['enabled' => true]);
return view('support');
});
TawkAPI.toggle();
app.css:
.tawk-button {
background: #your-color !important;
}
TAWK_SITE_ID: Fixed in v13.0.0, but ensure it’s set in .env to avoid blank pages. Test with:
php artisan config:clear
"mikebronner/laravel-tawk": "^12.0"
TAWK_ENABLE_CONSOLE_CAPTURE and TAWK_ENABLE_SCREENSHOT are true in config.window.TawkAPI = window.TawkAPI || {};
document.addEventListener('tawk:chatEnd', (e) => {
// Log chat end to your analytics
});
public function handle($request, Closure $next)
{
$request->merge(['tawk_properties' => ['custom_key' => 'value']]);
return $next($request);
}
Then access in AppServiceProvider:
Tawk::init($request->tawk_properties ?? []);
<script src="https://embed.tawk.to/YOUR_SITE_ID/default.js" async></script>
if (app()->environment('production') && !Route::current()->isSupportRoute()) {
Tawk::init(['enabled' => false]);
}
How can I help you explore Laravel packages today?