1. Go to this page and download the library: Download gerardojbaez/messenger 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/ */
gerardojbaez / messenger example snippets
use Messenger;
// Sending a message to one user:
Messenger::from($user)->to($user)->message('Hey!');
// Sending a message to multiple users: (an array of user ids)
Messenger::from($user)->to([1,2,3,4])->message('Who want to chat?!');
// Sending a message to one thread: (perfect for replying to a specific thread!)
Messenger::from($user)->to($thread)->message('I\'ll be there');
'providers' => [
/**
* Third Party Service Providers...
*/
Gerardojbaez\Messenger\MessengerServiceProvider::class,
]
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Gerardojbaez\Messenger\Contracts\MessageableInterface;
use Gerardojbaez\Messenger\Traits\Messageable;
class User extends Authenticatable implements MessageableInterface
{
use Messageable;
// Import the facade
use Messenger;
Messenger::from($user)->to($user2)->message('Hey!')->send();
// Import the facade
use Messenger;
Messenger::from($user)->to([1,2,3,4,5])->message('Hey!')->send();
// Import the facade
use Messenger;
Messenger::from($user)->to($thread)->message('That\'s awesome!')->send();
public function index()
{
// Eager Loading - this helps prevent hitting the
// database more than the necessary.
$this->user->load('threads.messages.sender');
return view('messages.index', [
'threads' => $this->user->threads
]);
}