underthecocotree / laravel-chat
使用socket.io为laravel构建的聊天模块
0.1.3
2015-12-14 16:19 UTC
Requires
- php: >=5.5.9
- illuminate/support: ~5.0
- predis/predis: ^1.0
Requires (Dev)
- phpspec/phpspec: ~2.0
- phpunit/phpunit: 4.*
This package is auto-updated.
Last update: 2024-08-29 03:52:51 UTC
README
安装
config/app.php
// providers
Underthecocotree\LaravelChat\Providers\LaravelChatServiceProvider::class,
// aliases
'Chat' => Underthecocotree\LaravelChat\Facades\Chat::class,
EventServiceProvider
如果您想为socket触发事件,则使用它,聊天不需要
protected $listen = [
'Underthecocotree\LaravelChat\Events\UserHasRegistered' => [
'Underthecocotree\LaravelChat\Listeners\Email@welcome',
],
Artisan publish views
artisan vendor:publish
## use force if you want to overwrite
artisan vendor:publish --force
npm依赖
npm install express ioredis redis socket.io --save
配置
config/broadcasting.php
'default' => env('BROADCAST_DRIVER', 'redis'),
运行
服务器
如果服务崩溃,需要monit来保持服务运行
node assets/js/socket.js
# debug mode
node underthecocotree/laravel-chat/src/resources/assets/js/socket.js --debug
聊天前端
在route.php中作为独立使用
// pass a room name to the facade - default is room
Route::get('/chat', function () {
return Chat::standalone();
});
Route::get('/standalone-room', function () {
return Chat::standalone('standalone-room');
});
// Pass a username to the facade, default is Anonymous
// $user = \Auth::user();
// return Chat::standalone('standalone-room', $user->name);
return Chat::standalone('standalone-room', 'Iordanis');
在blade模板中作为部分使用
// defautl name is room
{!! Chat::partial() !!}
// provide a name for the room
{!! Chat::partial('new-room') !!}
or @include('chat::partial-chat')