1. Go to this page and download the library: Download inani/messager library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Inani\Messager\Helpers\MessageAccessible;
use Inani\Messager\Helpers\TagsCreator;
class User extends Model
{
use MessageAccessible, TagsCreator;
...
}
$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);
$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();
// 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();
// Set the selected message(or id of messages as read)
$count = $userB->received()->select($message)->readThem();
// 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();
// 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();
// Get the draft messages for UserA
$messages = $userA->sent()->inDraft()->get().
// 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();
// 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);
// 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();
//
// To remove the tag from the message
$bool = $message->concerns($user)->removeTag();
php artisan vendor:publish
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.