PHP code example of rohitshakya / laravel-beacon

1. Go to this page and download the library: Download rohitshakya/laravel-beacon 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/ */

    

rohitshakya / laravel-beacon example snippets


$user->notify(new SomeNotification());
$reseller->notify(new SomeNotification());
$employee->notify(new SomeNotification());

return [

    'views' => [
        'inbox' => 'beacon::inbox.default',
        'item'  => 'beacon::item.default',
    ],

    'topbar' => [
        'limit' => 8,
    ],

    'realtime' => [
        'enabled'         => true,
        'resolver'        => \RohitShakya\Beacon\Support\DefaultChannelResolver::class,
        'channel_pattern' => '{class}.{id}',
        'channels'        => [
            // \App\Models\User::class => 'App.Models.User.{id}',
        ],
        'browser_event'   => 'beacon:notification',
    ],

    'notifications' => [
        // \App\Notifications\InvoicePaid::class => [...],
    ],
];

'views' => [
    'inbox' => 'beacon::inbox.default',
    'item'  => 'beacon::item.default',
],

'topbar' => [
    'limit' => 8,
],

'realtime' => [
    'enabled'         => true,
    'resolver'        => \RohitShakya\Beacon\Support\DefaultChannelResolver::class,
    'channel_pattern' => '{class}.{id}',
    'channels'        => [
        // \App\Models\User::class => 'App.Models.User.{id}',
    ],
    'browser_event'   => 'beacon:notification',
],

'realtime' => [
    'channels' => [
        \App\Models\Reseller::class => 'tenants.{id}.reseller',
        \App\Models\Employee::class => 'org.employee.{id}',
    ],
],

namespace App\Beacon;

use RohitShakya\Beacon\Support\Contracts\ChannelResolver;

class TenantChannelResolver implements ChannelResolver
{
    public function resolve($notifiable = null): ?string
    {
        $notifiable = $notifiable ?: auth()->user();
        if (! $notifiable) {
            return null;
        }

        // Whatever runtime logic you need — DB lookup, tenant scope, etc.
        return sprintf(
            'tenants.%s.%s.%s',
            tenant()->id,
            str_replace('\\', '.', $notifiable::class),
            $notifiable->getKey(),
        );
    }
}

// config/beacon.php
'realtime' => [
    'enabled'  => true,
    'resolver' => \App\Beacon\TenantChannelResolver::class,
    // channel_pattern / channels are ignored — your resolver controls the name
],

$user->notify(new TestNotification());
$reseller->notify(new TestNotification());
bash
php artisan vendor:publish --tag=beacon-config
bash
php artisan vendor:publish --tag=beacon-views
bash
php artisan vendor:publish --tag=beacon-views