• Stars
    star
    153
  • Rank 243,368 (Top 5 %)
  • Language
    PHP
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A convenient way to handle messages between users in a simple way

(NOT MAINTAINED)

Laravel Messager

A convenient way to handle messages between users in a simple way

Table of Contents

  1. Installation
  2. Setup a Model
  3. Creating & Sending Messages
    1. Creating a message
    2. Sending the message
    3. Responding the message
    4. Drafting a message
  4. Working with Messages
    1. Getting messages between users
    2. Read messages
    3. Unread messages
    4. Draft messages
  5. Tags
    1. Create and Edit tags
    2. Assign tag to message
    3. Change and get tag of a message
    4. Remove a tag from a message

Installation:

First, install the package through Composer.

composer require inani/messager

Then include the service provider inside config/app.php.

'providers' => [
    ...
    Inani\Messager\MessagerServiceProvider::class,
    ...
];

Publish config and migrations

php artisan vendor:publish

Setup a Model

To setup a model all you have to do is add (and import) the MessageAccessible trait.

use Inani\Messager\Helpers\MessageAccessible;
use Inani\Messager\Helpers\TagsCreator;
class User extends Model
{
    use MessageAccessible, TagsCreator;
    ...
}

Creating & sending Messages

Creating a message

$receiver = User::find(1); 

// Message Data
$messageData = [
	'content' => 'Hello all this is just a test', // the content of the message
	'to_id' => $receiver->getKey(), // Who should receive the message
];

list($message, $user) = App\User::createFromRequest($messageData);

Sending the message

$sender = User::find(2);

$sent = $sender->writes($message)
                 ->to($user)
                 ->send();
		 
// send to multiple users the same message
// can execpt a user|array of users| array of ids| or array of users and ids
$sent = $sender->writes($message)
                 ->to($user)
		 ->cc([$user1, $user2])
		 ->cc([$user3->id, $user4->id])
                 ->send();

Responding the message

$sender = User::find(2);

$sent = $user->writes($newMessage)
                 ->to($sender)
		 ->responds($message)
                 ->send();

Drafting a message

$sender = User::find(2);

$draft = $sender->writes($message)
                  ->to($user)
                  ->draft()
                  ->keep();

Working with Messages

Once you've got messages you need to do something with them.

Getting messages between users

// Users
$userA = App\User::find(1);
$userB = App\User::find(2);

// Get seen messages sent from UserB to UserA
$messages = $userA->received()->from($userB)->seen()->get();

// OR you can pass an array of IDs 
$messages = $userA->received()->from([2, 3, 4, 5])->seen()->get();

Read messages

// Set the selected message(or id of messages as read)
$count = $userB->received()->select($message)->readThem();

Unread messages

// Get unread messages from UserB to User A
$messages = $userA->received()->from($userB)->unSeen()->get();

// Marking them as read
$messages = $userA->received()->from($userB)->unSeen()->readThem();

// check out if a conversation has new messages
$bool = $userA->received()->conversation($message)->hasNewMessages();

// Get the number of conversations that have new messages in it
$number = $userA->received()->unSeenConversations();

Sent messages

// Get unread messages from UserA to UserB
$messages = $userA->sent()->to($userB)->get();

// OR you can pass an array of IDs
$messages = $userA->received()->to([2, 3, 4, 5)->get();

Draft messages

// Get the draft messages for UserA
$messages = $userA->sent()->inDraft()->get().

Tags

You can tag (or structure your messages in different categories).

Create and Edit tags

each user can make any number of tags.

// create a new tag, $data can be (Tag instance, array, Request)
$tag = $userA->addNewTag($data);

// Modify the attributes of a tag
$user->tag($tag)->name("social")->color("#ffff")->apply();

Assign tag to message

Once you have the message and the tag

// you'll need the instance of user(to check if sender or receiver)
// $user and $tag can be ids or instance of User, Tag classes
$bool = $message->concerns($user)->putTag($tag);

Change and get tag of a message

// to change the tag just use the same method
$bool = $message->concerns($user)->putTag($tag);

// to get the tag of the message, null if not tagged
$tagOrNull = $message->concerns($user)->getTag();
// 

Remove a tag from a message

// To remove the tag from the message
$bool = $message->concerns($user)->removeTag();

More Repositories

1

larapoll

A Laravel package to manage your polls
PHP
260
star
2

maravel-permissions

Because in the Maravelous univer every user deserves super power
PHP
142
star
3

laravel-nova-configuration

Use Configuration inputs instead of the env/config files. Good news for the clients!
Vue
40
star
4

chibi

A mini PHP framework
PHP
37
star
5

oxfordapi-wrapper

A PHP/Laravel Wrapper for oxford dictionary API
PHP
27
star
6

nova-resource-maker

A Nova tool that will help you to generate fields array for the resource.
PHP
25
star
7

LazyBelongsToMany

A lightweight implementation of Laravel's belongs To many
PHP
24
star
8

PHPValidate

A light library to validate inputs
PHP
11
star
9

Dental

A Dental App built using Laravel 5.2
HTML
11
star
10

laravel-same-request

The Missing check on Laravel Request Unicity.
PHP
10
star
11

corona-wash-reminder

A mobile app to remind you to wash your hand
TypeScript
8
star
12

geeksblabla

This is my Nuxt Js version of Geeksblabla of #DevC
JavaScript
8
star
13

laravel-controllers-generator

A Laravel package that will generate for you controllers used in routes
PHP
7
star
14

vuejs-101

HTML
4
star
15

parser

PHP
4
star
16

filters

PHP
3
star
17

chibi-orm

PHP
2
star
18

chibi-console

PHP
2
star
19

psd-to-html

PSDs converted to HTML/CSS
CSS
1
star
20

php-array-every-day

A repo where I put every day some code to understand and get used to the important arrays method
PHP
1
star
21

The-Coding-Train

Notes&Codes of The Coding Train Tutorials
Processing
1
star
22

docker-101

PHP
1
star
23

webpack-101

JavaScript
1
star
24

Uploader

a simple Class to make your life easier while handling Uploads
1
star
25

chibi-app

The basic app to be used with chibi framework
PHP
1
star
26

presta-module

PHP
1
star
27

realtime-with-socket-io

Real time chat with Socketio & Vuejs
HTML
1
star