Skip to content

Instantly share code, notes, and snippets.

@ammezie
Created September 30, 2019 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ammezie/530169be0b2d64b4f4acbfb9388f2e3c to your computer and use it in GitHub Desktop.
Save ammezie/530169be0b2d64b4f4acbfb9388f2e3c to your computer and use it in GitHub Desktop.
// app/Http/Controllers/Auth/RegisterController.php
// first import StreamChat PHP client
use GetStream\StreamChat\Client as StreamClient;
protected function registered($user){
$client = new StreamClient(env("MIX_STREAM_API_KEY"), env("MIX_STREAM_API_SECRET"), null, null, 9);
$username = explode('@', $user->email)[0];
// create the user on Stream Chat
$client->updateUser([
'id' => $username,
'name' => $user->name,
]);
// create channel
$channel = $client->Channel("messaging", "chatroom");
// channel is created by `admin` user
$channel->create('admin');
// then add the newly registered user as a member
$channel->addMembers([$username]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment