Permalink
Browse files

ユーザがログインしたことをbroadcastするPrivateChannelの追加

  • Loading branch information...
adjust-fuchigami committed Nov 6, 2017
1 parent f95cbea commit 0f8fc5acdb14f5b2459741aa42d7673281b7380e
Showing with 49 additions and 3 deletions.
  1. +46 −0 app/Events/BroadcastUserLogined.php.php
  2. +1 −1 config/app.php
  3. +2 −2 routes/channels.php
@@ -0,0 +1,46 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use App\User;
class BroadcastUserLogined implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
private $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('user.logined.'.$this->user->id);
}
public function broadcastWith()
{
return [
'client_ip' => request()->ip(),
];
}
}
View
@@ -173,7 +173,7 @@
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
View
@@ -11,6 +11,6 @@
|
*/
Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
Broadcast::channel('user.logined.{userId}', function ($user, $userId) {
return $user->id === (int) $userId;
});

0 comments on commit 0f8fc5a

Please sign in to comment.