如何在Laravel 5.3中为两个不同的表(用户和管理员)设置多个身份验证.
默认情况下,Laravel具有用户模型.
我想使用 Channels 2 向特定的经过身份验证的用户发送通知。
在下面的代码中,我将通知作为广播发送,而不是我想向特定用户发送通知。
from channels.generic.websocket import AsyncJsonWebsocketConsumer
class NotifyConsumer(AsyncJsonWebsocketConsumer):
async def connect(self):
await self.accept()
await self.channel_layer.group_add("gossip", self.channel_name)
print(f"Added {self.channel_name} channel to gossip")
async def disconnect(self, close_code):
await self.channel_layer.group_discard("gossip", self.channel_name)
print(f"Removed {self.channel_name} channel to gossip")
async def user_gossip(self, event):
await self.send_json(event)
print(f"Got message {event} at {self.channel_name}")
Run Code Online (Sandbox Code Playgroud)