Skip to content
Chat/Message system for Laravel.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Merge pull request #7 from AlShahawi/master Mar 4, 2018
tests Fix Base TestCase Error Mar 2, 2018
.editorconfig Update .editorconfig Oct 17, 2016
.gitattributes Initial commit Aug 5, 2016
.gitignore Update .gititgnore Mar 3, 2018
.travis.yml Update travis Mar 2, 2018 Update changelog Mar 4, 2018
LICENSE Merge pull request #7 from AlShahawi/master Mar 4, 2018
composer.json Merge pull request #7 from AlShahawi/master Mar 4, 2018

Build Status Latest Version Software License


Chat/Message system for Laravel 5.x.

With Messenger:

  • Users can send and receive messages.
  • Users can participate in multiple conversations.
  • Users can send messages to one or multiple users.


use Messenger;

// Sending a message to one user:

// 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');




  • Laravel 5.x
  • PHP >=5.5


$ composer require gerardojbaez/messenger

Service Provider and Facade

If you are using laravel 5.5 and later, you can skip the following two steps since this package supports package auto-discovery feature.

Add the package to your application service providers in config/app.php file.

'providers' => [
	 * Third Party Service Providers...

Add the Facade to your aliases array:

'aliases' => [


	'Messenger' => Gerardojbaez\Messenger\Facades\Messenger::class,

Config file and Migrations

Publish package config file and migrations with the command:

$ php artisan vendor:publish --provider="Gerardojbaez\Messenger\MessengerServiceProvider"

Then run migrations:

$ php artisan migrate

Traits and Contracts

Add Gerardojbaez/Messenger/Traits/Messageable trait and Gerardojbaez/Messenger/Contracts/MessageableInterface contract to your Users model.

See the following example:


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;


Sending to One User


// Import the facade
use Messenger;


Sending to Multiple Users


// Import the facade
use Messenger;


Sending to Thread


// Import the facade
use Messenger;

Messenger::from($user)->to($thread)->message('That\'s awesome!')->send();

Get count of new messages

Get global count - new messages in all user threads:


echo $user->unreadMessagesCount;

Get count for a particular user thread:


echo $user->threads->first()->unreadMessagesCount;

Mark thread as read

To mark a thread as read:



Thread Dynamic Attributes

Threads dynamic attributes are attributes that doesn't come from the database, instead we generate them based on the data.

For example, threads doesn't have a title by itself, Messenger will create it based on the participants list.


  • $thread->title
  • $thread->creator to get the thread creator.
  • $thread->lastMessage to get the latest message in the thread.

Displaying user threads

The controller:

public function index()
    // Eager Loading - this helps prevent hitting the
    // database more than the necessary.

    return view('messages.index', [
        'threads' => $this->user->threads

The view:

<div class="panel panel-default">
    <div class="list-group">
        @if($threads->count() > 0)
            @foreach($threads as $thread)
                    <a href="#" class="list-group-item">
                        <div class="clearfix">
                            <div class="pull-left">
                                <span class="h5">{{ $thread->title }}</span>
                                @if($thread->unreadMessagesCount > 0)
                                    <span class="label label-success">{!! $thread->unreadMessagesCount !!}</span>
                            <span class="text-muted pull-right">{{ $thread->lastMessage->created_at->diffForHumans() }}</span>
                        <p class="text-muted no-margin">{{ str_limit($thread->lastMessage->body, 35) }}</p>


Preview of all user threads

Using Models

Messenger has 3 models:


You can use these as normal. For more details take a look to each model and the Gerardojbaez\Messenger\Traits\Messageable trait.

Config File

For now you can configure what models to use.


This package is free software distributed under the terms of the MIT license.

You can’t perform that action at this time.