Giter Club home page Giter Club logo

laravel-inbox's Introduction

Laravel Inbox

Internal messages between users in Laravel. Create an inbox system, in app messages, between users easily.

Latest Version Total Downloads License

Installation

This package can be installed through Composer.

composer require multicaret/laravel-inbox

If you don't use Laravel 5.5+ you have to add the service provider manually

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

You can publish the config-file with:

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

This is the contents of the published config file:

<?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',
        ],
    ],
];

Usage

First, we need to use HasInbox trait so users can have their inbox:

<?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;
}

Get user threads:

$user->threads()

Get unread messages:

$thread = $user->unread()

Get the threads that have been sent by a user:

$thread = $user->sent()

Get the threads that have been sent to the user:

$thread = $user->received()

Send new thread:

  • subject(): your message subject
  • writes(): your message body
  • to(): array of users ID that you want them to receive your message
  • send(): to send your message
$thread = $user->subject($request->subject)
            ->writes($request->body)
            ->to($request->recipients)
            ->send();

Reply for thread:

  • reply() an object for your thread
$message = $user->writes($request->body)
                ->reply($thread);

Check if the thread has any unread messages:

if ($thread->isUnread())

License

The MIT License (MIT). Please see License File for more information.

laravel-inbox's People

Contributors

mkwsra avatar pheeque avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.