marksihor/laravel-messaging

Simple laravel messaging
2,239
Install
composer require marksihor/laravel-messaging
Latest Version:1.12
License:MIT
Last Updated:Jul 9, 2020
Links: GitHub  ·  Packagist
Maintainer: marksihor

laravel-messaging

Simple messaging between users.

Installing

$ composer require marksihor/laravel-messaging -vvv

Migrations

This step is optional, if you want to customize the tables, you can publish the migration files:

$ php artisan vendor:publish --provider="MarksIhor\\LaravelMessaging\\MessagingServiceProvider" --tag=migrations

Usage

Use trait on User Model

MarksIhor\LaravelMessaging\Traits\Messageable

<?php

namespace App\User;

<...>
use MarksIhor\LaravelMessaging\Traits\Messageable;

class User extends Authenticatable
{
    <...>
    use Messageable;
    <...>
}

API


$user()->chats; // get all chats available for given user (with last message)
$user()->chatsUnread; // get all unread chats
$user()->chatsRead; // get all read chats
$user()->chat(1); // get one chat with all messages

$user()->sendMessageToChat(1, ['text' => 'message to chat']); // send message to specified chat (if user is in the chat)
$user()->sendMessageToUser($recipient, ['text' => 'message to user', 'link' => 'https://some.link']); // send message to specified recipient

If You need manually to change "read" status, You can do the following:


use MarksIhor\LaravelMessaging\Services\MessagingService;

<...>
MessagingService::markReadForUser($chatId, $userId, $type === 'read' ? 1 : 0)
<...>

License

MIT

Related Packages

gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444