2017 © Pedro Peláez
 

composer-plugin messages-manager

The package provides an easy way to implementing a messages manager into your laravel project

image

ousamox/messages-manager

The package provides an easy way to implementing a messages manager into your laravel project

  • Saturday, January 13, 2018
  • by ousamox
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

MessagesManager

This package support only Laravel 5.x versions, (*1)

Installation

Add MessagesManager package to your composer.json file to require it :, (*2)

    require : {
        "laravel/framework": xxxx,
        ...
        "ousamox/messages-manager": "master"
    }

Update Composer :, (*3)

$ composer update

The next required step is to add the service provider to config/app.php :, (*4)

    'providers' => array(
        ...
        'Ousamox\MessagesManager\Providers\MessagesManagerProvider'
    )

Alias the PushNotification facade by adding it to the aliases array in the config/app.php file :, (*5)

    'aliases' => array(
        ...
        'OMessage' => 'Ousamox\MessagesManager\Facades\OMessage'
    )

Configuration

Publish Files

Publish OMM config and migration files in your application with :, (*6)

$ php artisan vendor:publish --tag=omm

This will generate a config file in config/omm.php like this :, (*7)

return [
    'models' => [
        'channel' => [
            'table_name' => 'OMM_CHANNELS',
            'class' => \Ousamox\MessagesManager\Models\Channel::class,
        ],
        'device' => [
            'table_name' => 'OMM_DEVICES',
            'class' => \Ousamox\MessagesManager\Models\Device::class,
        ],
        'message' => [
            'table_name' => 'OMM_MESSAGES',
            'class' => \Ousamox\MessagesManager\Models\Message::class,
        ],
        'message_seen' => [
            'table_name' => 'OMM_MESSAGE_SEENS',
            'class' => \Ousamox\MessagesManager\Models\MessageSeen::class,
        ],
        'message_file' => [
            'table_name' => 'OMM_MESSAGE_FILES',
            'class' => \Ousamox\MessagesManager\Models\MessageFile::class,
        ],
        'session' => [
            'table_name' => 'OMM_SESSIONS',
            'class' => \Ousamox\MessagesManager\Models\Session::class,
        ],
        'user' => [
            'table_name' => 'OMM_USERS',
            'class' => \Ousamox\MessagesManager\Models\User::class,
        ],
    ],
    'channels_duplication' => env('OMM_CHANNELS_DUPLICATION',false),
];

This will generate also a migration file in database/migrations contains all tables that we must have in our database., (*8)

Configure files

We can customise the name of our tables by editing the models.<entity>.table_name value in config/omm.php, (*9)

We can alse customise the main model class for each entity by editing the models.<entity>.class value in config/omm.php :, (*10)

Example :, (*11)

config/omm.php :, (*12)

return [
    'models' => [
        'channel' => [
            'table_name' => 'app_channels',
            'class' => App\Models\Channel::class,
        ],
        ...

app/models/Channel.php :, (*13)

namespace App\Models;

use Ousamox\MessagesManager\Models\Channel as BaseChannel;

class Channel extends BaseChannel
{
    // Add or Override the main behavior of this class without touching its defined properties or attributes
    ...
}

The last step is generating tables by running this command :, (*14)

$ php artisan migrate

Congratulations, you have successfully installed MessagesManager in your project !, (*15)

Usage

1- Authentification is required when using these methods, (*16)

2- Pagination must be available on the next release, (*17)

Get All Channels (conversations)

To get the list of channels :, (*18)

$channels = \OMessage::getChannels();

Get Messages by channel (conversation)

To get the list of channels :, (*19)

// $value must be an integer (channel ID) or a Channel Object
$messages = \OMessage::getMessagesByChannel($value);

Send Message

Send First Message in new channel, (*20)

$messages = \OMessage::sendMessageNewChannel($messageData: array, $channelData: array $toUsers: array, $files = []);

Parameters :, (*21)

Parameter Description
messageData [Required] data array should respect the following structure :
[
   'content' => 'Hello World', // REQUIRED
   'sent_from_lat' => 3.993843, // OPTIONAL (MAPS Latituude)
   'sent_from_long' => 23.222843, // OPTIONAL (MAPS Longitude)
   ... // Other attributes added in entity : message
]
Parameter Description
channelData [Required] data array should respect the following structure :
[
   'subject' => 'New Channel', // OPTIONAL
   .. // Other attributes added in entity : channel 
]
Parameter Description
toUsers [Required] array of users ID that must receive message (one or many)
files [Optional] array of files to join (one or many)

Send Message in existing channel, (*22)

$messages = \OMessage::sendMessageExistingChannel($messageData: array, $channel: ChannelModel|int, $files = []);

Parameters :, (*23)

Parameter Description
messageData [Required] data array should respect the following structure :
[
   'content' => 'Hello World', // REQUIRED
   'sent_from_lat' => 3.993843, // OPTIONAL (MAPS Latituude)
   'sent_from_long' => 23.222843, // OPTIONAL (MAPS Longitude)
   ... // Other attributes added in entity : message
]
Parameter Description
channel [Required] Channel object or channel ID
files [Optional] array of files to join (one or many)

Add users to an existing channel, (*24)

Only channel creator could attach users to it, (*25)

$messages = \OMessage::addUsersToChannel($channel: ChannelModel|int, $users: array);

Parameters :, (*26)

Parameter Description
channel [Required] Channel object or channel ID
users [Required] array of users ID that must attach this channel

The Versions

13/01 2018

dev-master

9999999-dev

The package provides an easy way to implementing a messages manager into your laravel project

  Sources   Download

MIT

The Requires

 

by Oussama BOUISFI

laravel messages manager chat ousamox oussama bouisfi