multicaret/laravel-inbox

此包最新版本(8.0.0)没有可用的许可证信息。

Laravel消息和收件箱系统

8.0.0 2021-10-13 08:40 UTC

This package is auto-updated.

Last update: 2024-09-13 15:09:18 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)。有关更多信息,请参阅许可证文件