marksihor / laravel-messaging
简单的 Laravel 消息系统
1.12
2020-07-09 08:24 UTC
Requires
- laravel/framework: ~7.0
README
用户间简单消息。
安装
$ composer require marksihor/laravel-messaging -vvv
迁移
此步骤是可选的,如果您想自定义表,您可以发布迁移文件
$ php artisan vendor:publish --provider="MarksIhor\\LaravelMessaging\\MessagingServiceProvider" --tag=migrations
使用方法
在用户模型上使用特性
MarksIhor\LaravelMessaging\Traits\Messageable
<?php namespace App\User; <...> use MarksIhor\LaravelMessaging\Traits\Messageable; class User extends Authenticatable { <...> use Messageable; <...> }
API
$user()->chats; // get all chats available for given user (with last message) $user()->chatsUnread; // get all unread chats $user()->chatsRead; // get all read chats $user()->chat(1); // get one chat with all messages $user()->sendMessageToChat(1, ['text' => 'message to chat']); // send message to specified chat (if user is in the chat) $user()->sendMessageToUser($recipient, ['text' => 'message to user', 'link' => 'https://some.link']); // send message to specified recipient
如果您需要手动更改 "已读" 状态,可以执行以下操作
use MarksIhor\LaravelMessaging\Services\MessagingService; <...> MessagingService::markReadForUser($chatId, $userId, $type === 'read' ? 1 : 0) <...>
许可证
MIT