digitlimit/inbox

此包最新版本(v1.0.0)无可用许可信息。

Laravel消息和收件箱系统

v1.0.0 2023-05-21 15:12 UTC

This package is auto-updated.

Last update: 2024-09-21 17:57:43 UTC


README

此Laravel包可以帮助您轻松创建收件箱系统并方便地在用户之间发送消息。此包是从https://github.com/DigitlimitLab/laravel-inbox分叉而来的。

变更记录

  • 修复收件箱列表问题,现在收件箱只显示收到的消息
  • https://ui-avatars.com/添加默认头像
  • 修复收件箱和已发送项目标签页上的标签
  • 为已发送项目添加独立的路由和控制器

安装

此包可以通过Composer安装。

composer require digitlimit/laravel-inbox

如果您不使用Laravel 5.5+,则需要手动添加服务提供者

// config/app.php
'providers' => [
    ...
    Digitlimit\Inbox\InboxServiceProvider::class,
    ...
];

您可以发布迁移、配置、视图、语言文件

php artisan vendor:publish --provider="Digitlimit\Inbox\InboxServiceProvider" 

这是发布配置文件的内容

<?php

return [

    'paginate' => 10,

    /*
    |--------------------------------------------------------------------------
    | Inbox Route Group Config
    |--------------------------------------------------------------------------
    |
    | ..
    |
    */

    'route' => [
        'prefix' => 'inbox',
        'middleware' => ['web', 'auth'],
        'name' => null
    ],

    /*
    |--------------------------------------------------------------------------
    | Inbox Tables Name
    |--------------------------------------------------------------------------
    |
    | ..
    |
    */

    'tables' => [
        'threads' => 'threads',
        'messages' => 'messages',
        'participants' => 'participants',
    ],

    /*
    |--------------------------------------------------------------------------
    | Models
    |--------------------------------------------------------------------------
    |
    | If you want to overwrite any model you should change it here as well.
    |
    */

    'models' => [
        'thread' => Digitlimit\Inbox\Models\Thread::class,
        'message' => Digitlimit\Inbox\Models\Message::class,
        'participant' => Digitlimit\Inbox\Models\Participant::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Inbox Notification
    |--------------------------------------------------------------------------
    |
    | Via Supported: "mail", "database", "array"
    |
    */

    'notifications' => [
        'via' => [
            'mail',
        ],
    ],
];

用法

首先,我们需要使用HasInbox特性,以便用户可以拥有他们的收件箱

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Digitlimit\Inbox\Traits\HasInbox;

class User extends Authenticatable
{
    use Notifiable, HasInbox;
}

获取用户线程

$user->threads()

获取未读消息

$thread = $user->unread()

获取用户发送的线程

$thread = $user->sent()

获取发送给用户的线程

$thread = $user->received()

发送新线程

  • subject():您的消息主题
  • writes():您的消息正文
  • to():您想接收消息的用户ID数组
  • send():发送您的消息
$thread = $user->subject($request->subject)
            ->writes($request->body)
            ->to($request->recipients)
            ->send();

回复线程

  • reply()回复线程的对象
$message = $user->writes($request->body)
                ->reply($thread);

检查线程是否有未读消息

if ($thread->isUnread())

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件