PHP code example of ruvelo / laravel-inbox

1. Go to this page and download the library: Download ruvelo/laravel-inbox library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ruvelo / laravel-inbox example snippets


class InvoicePaid extends Notification
{
    public function via(object $notifiable): array
    {
        return ['mail', 'database'];
    }

    public function toArray(object $notifiable): array
    {
        return [
            'title' => "Invoice {$this->invoice->number} paid",
            'body' => "{$this->invoice->customer} paid {$this->invoice->total}.",
            'url' => route('invoices.show', $this->invoice),
            'icon' => '💸',
        ];
    }
}

use Ruvelo\Inbox\Contracts\InboxNotification;
use Ruvelo\Inbox\InboxMessage;

class TeammateJoined extends Notification implements InboxNotification
{
    public function via(object $notifiable): array
    {
        return ['database'];
    }

    public function toInbox(object $notifiable): InboxMessage
    {
        return InboxMessage::make("{$this->user->name} joined your team")
            ->withUrl(route('team'))
            ->withActor($this->user->name);
    }
}

Inbox::present(ExportReady::class, fn (array $data) => InboxMessage::make(
    'Your export is ready',
    body: "{$data['rows']} rows",
    url: route('exports.show', $data['export_id']),
    icon: '📦',
));

use Ruvelo\Inbox\Inbox;

Inbox::preferences([
    InvoicePaid::class => [
        'label' => 'Invoice paid',
        'description' => 'When a customer pays one of your invoices.',
        'group' => 'Billing',
        'channels' => ['mail', 'database'],
        'defaults' => ['mail' => false],   // off until they turn it on
    ],
    SecurityAlert::class => [
        'label' => 'Security alerts',
        'channels' => ['mail'],
        '

use Ruvelo\Inbox\Notifications\RespectsInboxPreferences;

class InvoicePaid extends Notification
{
    use RespectsInboxPreferences;

    public function via(object $notifiable): array
    {
        return $this->preferredChannels($notifiable, ['mail', 'database']);
    }
}

'layout' => 'layouts.app',
'section' => 'content',

use Ruvelo\Inbox\Inbox;

Inbox::unreadCount($user);              // one indexed COUNT query
Inbox::latest($user, 5);                // newest first, read or not
Inbox::query($user)->whereNull('read_at')->paginate();
Inbox::find($user, $id);                // null if it isn't theirs
Inbox::markRead($notification);         // false if it already was
Inbox::markUnread($notification);
Inbox::markAllRead($user);              // one query; returns how many
Inbox::delete($notification);
Inbox::message($notification);          // how it looks: an InboxMessage
Inbox::present(Type::class, fn (array $data, Notification $n) => InboxMessage::make('…'));
Inbox::preferences([...]);              // register switchable types
Inbox::wants($user, InvoicePaid::class, 'mail');
Inbox::filterChannels($user, InvoicePaid::class, ['mail', 'database']);
Inbox::preferencesFor($user);           // [type => [channel => bool]], defaults filled in
Inbox::updatePreferences($user, [InvoicePaid::class => ['mail' => true]]);

use Ruvelo\Inbox\Models\Notification;

Notification::factory()->to($user)->count(3)->create();
Notification::factory()->to($user)->read()->ofType(InvoicePaid::class)
    ->message(InboxMessage::make('Invoice paid', url: '/invoices/1'))->create();

php artisan vendor:publish --tag=inbox-config

php artisan vendor:publish --tag=inbox-views
json
{
  "id": "9d1c…", "type": "App\\Notifications\\InvoicePaid", "type_label": "Invoice paid",
  "title": "Invoice INV-2288 paid", "body": "Bluefin Studio paid €4,800.00.", "url": "/invoices/INV-2288",
  "open_url": "https://app.test/inbox/9d1c…/open", "icon": "💸", "actor": null, "initials": "I",
  "read": false, "read_at": null, "created_at": "2026-10-08T09:12:00+00:00",
  "time_ago": "48 minutes ago", "day": "Today", "payload": { "…": "the stored data" }
}