Installation
composer require classiebit/addchat-laravel
Publish the package assets and config:
php artisan vendor:publish --provider="Classiebit\Addchat\AddchatServiceProvider"
Database Migration Run the migrations to create the required tables:
php artisan migrate
Configuration
Update .env with your database settings (already configured in config/addchat.php).
Ensure users table has id and email columns (or adjust config to match your user model).
First Integration Add the chat widget to your Blade template:
@addchat
Or manually include the JS/CSS:
<script src="{{ asset('vendor/addchat/js/addchat.js') }}"></script>
<link href="{{ asset('vendor/addchat/css/addchat.css') }}" rel="stylesheet">
Initial User Setup
Assign a role to your first user (e.g., admin or customer) via the users table or a seed:
$user->addchat_role = 'admin'; // or 'customer'
$user->save();
@addchat) on both users’ browsers.users table with addchat_role (e.g., admin, customer, support).// In a User model observer or registration controller
event(new Registered($user));
$user->addchat_role = 'customer';
$user->save();
addchat_messages table.database channel (polling-based).AddchatMessageSent events.// Override default event handling in your app.js
window.Addchat = window.Addchat || {};
window.Addchat.onMessage = function(message) {
console.log('Custom logic:', message);
// Extend with your own UI updates
};
addchat_groups table to create departments (e.g., "Support", "Sales").// Create a group via a controller
$group = \Classiebit\Addchat\Models\Group::create([
'name' => 'Customer Support',
'description' => 'Dedicated support team',
]);
// Assign users to the group
$group->users()->attach([1, 2, 3]); // User IDs
addchat_group_user pivot table.addchat_role to restrict access:
support role can see all users.customer role only sees other customers or support agents.// In a middleware or policy
public function authorizeSupport($user) {
return $user->addchat_role === 'support';
}
public_path() or Laravel Mix.public/vendor/addchat/:
cp -r vendor/classiebit/addchat/resources/views public/vendor/addchat/
resources/views/vendor/addchat/widget.blade.php).// resources/js/addchat.js
window.Addchat = {
theme: {
primary: '#3498db',
secondary: '#2ecc71'
}
};
// routes/api.php
Route::middleware('auth:api')->get('/addchat/messages', [\Classiebit\Addchat\Http\Controllers\MessageController::class, 'index']);
fetch('/api/addchat/messages')
.then(response => response.json())
.then(messages => console.log(messages));
Database Polling Lag
config/addchat.php polling_interval (default: 3000ms) or implement a queue worker for notifications:
// app/Providers/AppServiceProvider.php
public function boot() {
\Classiebit\Addchat\Events\AddchatMessageSent::class,
\Classiebit\Addchat\Events\AddchatTyping::class,
];
}
User Model Mismatch
users table has id and email. Custom user models may break auth.'user_model' => App\Models\CustomUser::class,
'user_id_field' => 'uuid', // If using UUIDs
CSRF Token Conflicts
@csrf is in your Blade layout or pass the token manually:
window.Addchat.csrfToken = '{{ csrf_token() }}';
Group Permissions Overlap
addchat_group_user pivot table to enforce one-to-many relationships explicitly.Asset Loading Order
@addchat at the end of your <body> or ensure dependencies are loaded first.Check Events Listen for broadcast events in Tinker:
php artisan tinker
>>> \Classiebit\Addchat\Events\AddchatMessageSent::dispatch(new \Classiebit\Addchat\Events\AddchatMessageSent($message));
Verify the event fires and notifications are queued.
Log Database Queries Enable Laravel debugging:
DB_DEBUG=true
Check for missing or malformed queries in storage/logs/laravel.log.
Widget Visibility Hide the widget conditionally:
@auth
@addchat
@endauth
Or via JS:
document.addEventListener('DOMContentLoaded', function() {
if (!window.user) {
document.querySelector('.addchat-widget').style.display = 'none';
}
});
Custom Message Types
Extend the addchat_messages table and override the Message model:
namespace App\Models;
use Classiebit\Addchat\Models\Message as BaseMessage;
class Message extends BaseMessage {
protected $casts = [
'is_read' => 'boolean',
'custom_field' => 'string', // Add your own fields
];
}
Update config/addchat.php:
'message_model' => App\Models\Message::class,
Webhook Integration Trigger external actions on message events:
// app/Providers/EventServiceProvider.php
protected $listen = [
\Classiebit\Addchat\Events\AddchatMessageSent::class => [
\App\Listeners\SendSlackNotification::class,
],
];
Rate Limiting Prevent spam via middleware:
// app/Http/Middleware/AddchatRateLimit.php
public function handle($request, Closure $next) {
$key = $request->ip().'|'.$request->user()->id;
if (cache()->has($key)) {
abort(429, 'Too many messages!');
}
cache()->put($key, true, now()->addMinutes(1
How can I help you explore Laravel packages today?