Installation Add the bundle via Composer:
composer require atm/inboxbundle
Register the bundle in config/app.php under providers:
Atm\InboxBundle\AtmInboxBundle::class,
Publish the bundle’s assets and configuration:
php artisan atm:inbox:install
Basic Setup
config/atm_inbox.php (e.g., default inbox types, notification channels).user_notifications) in the database via migrations or the admin interface (if provided).First Use Case: Displaying an Inbox
Inject the Atm\InboxBundle\Service\InboxService into a controller or service:
use Atm\InboxBundle\Service\InboxService;
public function showInbox(InboxService $inboxService)
{
$inboxItems = $inboxService->getInboxItems('user_notifications', auth()->id());
return view('inbox.show', compact('inboxItems'));
}
Render items in a Blade template:
@foreach($inboxItems as $item)
<div class="inbox-item">
<h4>{{ $item->title }}</h4>
<p>{{ $item->content }}</p>
<small>{{ $item->created_at->diffForHumans() }}</small>
</div>
@endforeach
Creating Inbox Items
Use the InboxService to create items programmatically:
$inboxService->createInboxItem([
'type' => 'user_notifications',
'user_id' => auth()->id(),
'title' => 'New Message',
'content' => 'You have a new message in your inbox.',
'metadata' => ['url' => '/messages/123'],
'is_read' => false,
]);
OrderShipped) to auto-populate the inbox:
event(new OrderShipped($order));
// In listener:
$inboxService->createInboxItem([...]);
Bulk Actions Mark items as read/unread or delete them:
$inboxService->markAsRead('user_notifications', [1, 2, 3]);
$inboxService->deleteItems('user_notifications', [1, 2, 3]);
Custom Inbox Types Extend the bundle by defining new inbox types in the database:
// Migration for a new type (e.g., 'system_alerts')
Schema::create('inbox_types', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->timestamps();
});
Register the type in config/atm_inbox.php:
'types' => [
'user_notifications' => ['label' => 'User Notifications'],
'system_alerts' => ['label' => 'System Alerts'],
],
Integration with Notifications Use Laravel’s notification system to auto-create inbox items:
use Atm\InboxBundle\Notification\InboxNotification;
Notification::route('inbox', 'user_notifications')
->notify(new InboxNotification('New Alert', 'Check your system alerts.'));
$inboxService->getInboxItems('user_notifications', auth()->id(), [
'read' => false,
'older_than_days' => 7,
]);
Route::post('/api/inbox/webhook', function (Request $request) {
$inboxService->createInboxItem([
'type' => 'system_alerts',
'user_id' => $request->user_id,
'title' => $request->title,
// ...
]);
});
php artisan vendor:publish --tag=atm-inbox-views
Missing Database Tables
php artisan migrate
inbox_items_user_notifications).Permission Issues
app/Http/Kernel.php:
'web' => [
\Atm\InboxBundle\Http\Middleware\CheckInboxPermissions::class,
// ...
],
Event Listeners Not Triggering
EventServiceProvider:
protected $listen = [
'order.shipped' => [
'Atm\InboxBundle\Listeners\CreateInboxItemListener',
],
];
Metadata Serialization
metadata field is JSON-encoded. Ensure your data is serializable:
'metadata' => json_encode(['key' => 'value']), // ✅
'metadata' => new \DateTime(), // ❌ (will fail)
config/atm_inbox.php to log item creation:
'debug' => env('APP_DEBUG', false),
toSql() to inspect generated queries:
$query = $inboxService->getQueryBuilder('user_notifications', auth()->id());
dd($query->toSql(), $query->getBindings());
Custom Item Models
Extend the base InboxItem model to add fields:
class CustomInboxItem extends \Atm\InboxBundle\Entity\InboxItem
{
protected $attributes = [
'custom_field' => null,
];
}
Update the bundle’s configuration to use your model.
Override Services
Bind your custom service in config/services.php:
'inbox' => [
'service' => \App\Services\CustomInboxService::class,
],
Add Custom Actions Extend the inbox item actions (e.g., "Archive", "Share") by publishing the bundle’s assets and overriding the action logic:
php artisan vendor:publish --tag=atm-inbox-actions
$inboxItems = $inboxService->getInboxItems('user_notifications', auth()->id(), [
'paginate' => 20,
]);
user_id and type columns in the inbox_items table for large datasets:
Schema::table('inbox_items', function (Blueprint $table) {
$table->index('user_id');
$table->index('type');
});
How can I help you explore Laravel packages today?