inani/messager
Composer 安装命令:
composer require inani/messager
包简介
A simple package to handle messages
README 文档
README
(NOT MAINTAINED)
Laravel Messager
A convenient way to handle messages between users in a simple way
Table of Contents
Installation:
First, install the package through Composer.
composer require inani/messager
Then include the service provider inside config/app.php.
'providers' => [ ... Inani\Messager\MessagerServiceProvider::class, ... ];
Publish config and migrations
php artisan vendor:publish
Setup a Model
To setup a model all you have to do is add (and import) the MessageAccessible trait.
use Inani\Messager\Helpers\MessageAccessible; use Inani\Messager\Helpers\TagsCreator; class User extends Model { use MessageAccessible, TagsCreator; ... }
Creating & sending Messages
Creating a message
$receiver = User::find(1); // Message Data $messageData = [ 'content' => 'Hello all this is just a test', // the content of the message 'to_id' => $receiver->getKey(), // Who should receive the message ]; list($message, $user) = App\User::createFromRequest($messageData);
Sending the message
$sender = User::find(2); $sent = $sender->writes($message) ->to($user) ->send(); // send to multiple users the same message // can execpt a user|array of users| array of ids| or array of users and ids $sent = $sender->writes($message) ->to($user) ->cc([$user1, $user2]) ->cc([$user3->id, $user4->id]) ->send();
Responding the message
$sender = User::find(2); $sent = $user->writes($newMessage) ->to($sender) ->responds($message) ->send();
Drafting a message
$sender = User::find(2); $draft = $sender->writes($message) ->to($user) ->draft() ->keep();
Working with Messages
Once you've got messages you need to do something with them.
Getting messages between users
// Users $userA = App\User::find(1); $userB = App\User::find(2); // Get seen messages sent from UserB to UserA $messages = $userA->received()->from($userB)->seen()->get(); // OR you can pass an array of IDs $messages = $userA->received()->from([2, 3, 4, 5])->seen()->get();
Read messages
// Set the selected message(or id of messages as read) $count = $userB->received()->select($message)->readThem();
Unread messages
// Get unread messages from UserB to User A $messages = $userA->received()->from($userB)->unSeen()->get(); // Marking them as read $messages = $userA->received()->from($userB)->unSeen()->readThem(); // check out if a conversation has new messages $bool = $userA->received()->conversation($message)->hasNewMessages(); // Get the number of conversations that have new messages in it $number = $userA->received()->unSeenConversations();
Sent messages
// Get unread messages from UserA to UserB $messages = $userA->sent()->to($userB)->get(); // OR you can pass an array of IDs $messages = $userA->received()->to([2, 3, 4, 5)->get();
Draft messages
// Get the draft messages for UserA $messages = $userA->sent()->inDraft()->get().
Tags
You can tag (or structure your messages in different categories).
Create and Edit tags
each user can make any number of tags.
// create a new tag, $data can be (Tag instance, array, Request) $tag = $userA->addNewTag($data); // Modify the attributes of a tag $user->tag($tag)->name("social")->color("#ffff")->apply();
Assign tag to message
Once you have the message and the tag
// you'll need the instance of user(to check if sender or receiver) // $user and $tag can be ids or instance of User, Tag classes $bool = $message->concerns($user)->putTag($tag);
Change and get tag of a message
// to change the tag just use the same method $bool = $message->concerns($user)->putTag($tag); // to get the tag of the message, null if not tagged $tagOrNull = $message->concerns($user)->getTag(); //
Remove a tag from a message
// To remove the tag from the message $bool = $message->concerns($user)->removeTag();
inani/messager 适用场景与选型建议
inani/messager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.58k 次下载、GitHub Stars 达 152, 最近一次更新时间为 2017 年 01 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 inani/messager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 inani/messager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 154
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-03