1. Go to this page and download the library: Download nativephp/mobile-vibe 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/ */
nativephp / mobile-vibe example snippets
use NativePHP\Vibe\Facades\Vibe;
public function mount(): void
{
Vibe::channel('orders')->on('OrderShipped', function ($event) {
$this->status = $event->status; // $this is the component
});
}
#[\NativePHP\Vibe\Attributes\OnEcho('OrderShipped', channel: 'orders')]
public function shipped(string $status): void { ... }
// e.g. in AppServiceProvider::boot()
use NativePHP\Vibe\Facades\Vibe;
use Native\Mobile\Facades\SecureStorage;
Vibe::resolveTokenUsing(fn () => SecureStorage::get('api_token'));
// 1. The event — broadcastAs() keeps the client-side name short; the payload
// ($event->message on the device) comes from public properties or broadcastWith().
class OrderShipped implements ShouldBroadcast
{
public function __construct(public string $message) {}
public function broadcastOn(): Channel
{
return new PrivateChannel('orders.'.$this->orderId);
}
public function broadcastAs(): string
{
return 'OrderShipped';
}
}
// 2. routes/channels.php — authorize private channels (true/false)...
Broadcast::channel('orders.{orderId}', fn ($user, $orderId) => $user->canSee($orderId));
// 3. ...and presence channels, which must RETURN THE MEMBER ARRAY — this becomes
// channel_data in the auth response and is what here()/joining() receive as
// ['id' => ..., 'info' => [...]]. Returning true breaks the roster.
Broadcast::channel('room.{id}', fn ($user, $id) => ['id' => $user->id, 'name' => $user->name]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.