Skip to content

Commit

Permalink
real-time chat
Browse files Browse the repository at this point in the history
  • Loading branch information
hkp22 committed Jun 2, 2024
1 parent 2092d18 commit 962203b
Show file tree
Hide file tree
Showing 13 changed files with 1,529 additions and 205 deletions.
37 changes: 37 additions & 0 deletions app/Events/MessageSent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Events;

use App\Models\ChatMessage;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class MessageSent implements ShouldBroadcastNow
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(public ChatMessage $message)
{
//
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel("chat.{$this->message->receiver_id}"),
];
}
}
1 change: 1 addition & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
channels: __DIR__.'/../routes/channels.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"require": {
"php": "^8.2",
"laravel/framework": "^11.0",
"laravel/reverb": "@beta",
"laravel/tinker": "^2.9",
"qirolab/laravel-themer": "^2.3"
},
Expand Down
Loading

0 comments on commit 962203b

Please sign in to comment.