liliom/laravel-inbox

此包已被弃用,不再维护。作者建议使用 multicaret/laravel-inbox 包。
此包的最新版本(8.0.0)没有可用的许可证信息。

Laravel 消息和收件箱系统

8.0.0 2021-10-13 08:40 UTC

This package is auto-updated.

Last update: 2021-10-13 08:44:42 UTC


README

Laravel 用户之间的内部消息。轻松创建用户之间的收件箱系统和应用内消息。

Latest Version Total Downloads License

安装

此包可以通过 Composer 安装。

composer require multicaret/laravel-inbox

如果您不使用 Laravel 5.5+,您必须手动添加服务提供者

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

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="Multicaret\Inbox\InboxServiceProvider" --tag="config"

这是发布配置文件的内容

<?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' => Multicaret\Inbox\Models\Thread::class,
        'message' => Multicaret\Inbox\Models\Message::class,
        'participant' => Multicaret\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 Multicaret\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)。有关更多信息,请参阅 许可证文件