andheiberg/messenger
Composer 安装命令:
composer require andheiberg/messenger
包简介
Basic messaging package for laravel
README 文档
README
Basic Messaging System for Laravel4
Introduction
The main purpose of this package is providing an suited Foundation for extended communication platforms, based on laravel 4 (or compatible frameworks).
Overview
You have many users and they want to chat? Couldn't be simplier!
- Participants have many conversations
- A conversation belongs to many participants
- A message belongs to a single conversation
- A conversation consists of many Messages
- Participants latest read timestamp is stored
Installation
- Add
"andheiberg/messenger": "dev-master"to your composer.json - Run
composer update - Add
'Andheiberg\Messenger\MessengerServiceProvider',toapp/config/app.phpunderproviders - Run
php artisan messenger:setup - Add
use \Andheiberg\Messenger\Traits\UserCanMessage;inside your User model class
Usage
Congratulations! Now you can use the laravel4 messenger.
php artisan messenger:setup will publish a Conversation and a Message model to app/models. If you prefer to make them your self, just extend Pichkrement\Messenger\Models\Conversation and Pichkrement\Messenger\Models\Message.
Examples
Now you can use it like a pro.
/** * Display a listing of the resource. * * @return Response */ public function index() { $user = Auth::user(); $conversations = Conversation::forUser()->get(); if ($conversations->isEmpty()) { return Redirect::route('conversations.create'); } return Redirect::route('conversations.show', [$conversations->last()->id]); } /** * Show the form for creating a new resource. * * @return Response */ public function create() { $user = Auth::user(); $conversations = Conversation::forUser()->orderBy('updated_at', 'desc')->get(); return View::make('conversations.create', compact('conversations')); } /** * Store a newly created resource in storage. * * @return Response */ public function store() { $input = Input::all(); $conversation = Conversation::create([ 'subject' => $input['subject'], ]); $message = Message::create([ 'conversation_id' => $conversation->id, 'user_id' => Auth::user()->id, 'body' => $input['message'], ]); $sender = Participant::create([ 'conversation_id' => $conversation->id, 'user_id' => Auth::user()->id ]); if ($this->input->has('recipient')) { $recipient = User::where('email', $input['recipient'])->first(); Participant::create([ 'conversation_id' => $conversation->id, 'user_id' => $recipient->id, ]); } return Redirect::route('conversations.index'); } /** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $user = Auth::user(); $conversations = Conversation::forUser()->orderBy('updated_at', 'desc')->get(); $conversation = Conversation::find($id); // $me = Participant::me()->where('conversation_id', $conversation->id)->first(); // $me->last_read = new DateTime; // $me->save(); return View::make('conversations.show', compact('conversations', 'conversation')); } /** * Show the form for creating a new resource. * * @return Response */ public function createMessage($conversation) { return View::make('conversations.create'); } /** * Store a newly created resource in storage. * * @return Response */ public function storeMessage($conversation) { $message = Message::create([ 'conversation_id' => $conversation, 'user_id' => $this->auth->user()->id, 'body' => $this->input->input('message'), ]); return Redirect::route('conversations.show', $conversation); }
andheiberg/messenger 适用场景与选型建议
andheiberg/messenger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.62k 次下载、GitHub Stars 达 69, 最近一次更新时间为 2014 年 02 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 andheiberg/messenger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 andheiberg/messenger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 69
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2014-02-09