Simple user messaging package for Laravel

Overview

Build Status Scrutinizer Scrutinizer Coverage Latest Version Total Downloads Software License

Laravel Messenger

This package will allow you to add a full user messaging system into your Laravel application.

Leave some feedback

How are you using laravel-messenger?

Features

  • Multiple conversations per user
  • Optionally loop in additional users with each new message
  • View the last message for each thread available
  • Returns either all messages in the system, all messages associated to the user, or all message associated to the user with new/unread messages
  • Return the users unread message count easily
  • Very flexible usage so you can implement your own access control

Common uses

  • Open threads (everyone can see everything)
  • Group messaging (only participants can see their threads)
  • One to one messaging (private or direct thread)

Laravel Versions

Laravel Messenger
4.* 1.*
5.0-5.4 <= 2.16.2
5.5+ 2.*

Installation (Laravel 4.x - no longer actively supported)

Installation instructions for Laravel 4 can be found here.

Installation (Laravel 5.x)

composer require cmgmyr/messenger

Or place manually in composer.json:

"require": {
    "cmgmyr/messenger": "~2.0"
}

Run:

composer update

Add the service provider to config/app.php under providers:

'providers' => [
    Cmgmyr\Messenger\MessengerServiceProvider::class,
],

Note: If you are using Laravel 5.5, this step is unnecessary. Laravel Messenger supports Package Discovery.

Publish config:

php artisan vendor:publish --provider="Cmgmyr\Messenger\MessengerServiceProvider" --tag="config"

Update config file to reference your User Model:

config/messenger.php

Create a users table if you do not have one already. If you need one, the default Laravel migration will be satisfactory.

(Optional) Define names of database tables in package config file if you don't want to use default ones:

'messages_table' => 'messenger_messages',
'participants_table' => 'messenger_participants',
'threads_table' => 'messenger_threads',

Publish migrations:

php artisan vendor:publish --provider="Cmgmyr\Messenger\MessengerServiceProvider" --tag="migrations"

Migrate your database:

php artisan migrate

Add the trait to your user model:

use Cmgmyr\Messenger\Traits\Messagable;

class User extends Authenticatable {
    use Messagable;
}

Examples

Example Projects

Contributing?

Please format your code before creating a pull-request. This will format all files as specified in .php_cs:

vendor/bin/php-cs-fixer fix .

Security

If you discover any security related issues, please email Chris Gmyr instead of using the issue tracker.

Credits

Special Thanks

This package used AndreasHeiberg/laravel-messenger as a starting point.

Comments
  • How are you using laravel-messenger?

    How are you using laravel-messenger?

    Please leave a comment explaining how you are using this package. How many users are you supporting? What type of features have you had to implement to extend the base functionality of this package?

    *If you have any issues, please open up a new ticket. Please keep this thread for feedback only. Thanks!

    feedback 
    opened by cmgmyr 67
  • ErrorException in Builder.php line 2450 (for unread-count.blade.php)

    ErrorException in Builder.php line 2450 (for unread-count.blade.php)

    I got an error with the newThreadsCount() method in unread-count.blade.php. Working in Laravel 5.3 -- full error below:

    Call to undefined method Illuminate\Database\Query\Builder::newThreadsCount() (View: /var/www/html/test-site/resources/views/messenger/unread-count.blade.php)

    opened by rtd62 29
  • How can I call the calss?

    How can I call the calss?

    When I put the function {{Thread::userUnreadMessagesCount(auth()->user()->id)}} in the view I get the error below:

    local.ERROR: Class 'Thread' not found

    How can I resolve please?

    opened by omidMolaverdi 27
  • Table names prefixes

    Table names prefixes

    One more thing which I found very important for this package is has an ability to set table names prefixes. I'm not talking about global application's database table names prefixes. That's mostly ability to group tables which this package is used and prevent table names conflicts with other packages.

    For example what I want to see in my database: messenger_threads, messenger_participants, messenger_messages

    Table names could stay unchanged and don't have prefixes by default to not break current deployed applications.

    Raised this question because got one more task for future implementation where tables with such names are already exists: threads are used in Forums package and messages are used in Comments package.

    opened by antonkomarev 22
  • Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given

    Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given

    Hi there,

    I am getting the following issue whenever I run the messenger application and since I am new to Laravel I am not 100% sure what is causing this problem. I have tried Googling the error but I am not getting a clear answer on this.

    Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given

    Could you help?

    Thanks,

    Rich

    opened by shep1990 20
  • Messenger makes huge number of database queries in view file

    Messenger makes huge number of database queries in view file

    I've noticed in testing that creating multiple, say 10-20, messages results in hundreds of database queries using the example view, index.blade.php, most of them being repeat queries. This is happening in the foreach loop not surprisingly. I really don't think database calls should be happening in the view file (its not the MVC-way) so I'm wondering how the code base can be cleaned up.

    screen shot 2015-10-01 at 8 59 49 pm
    opened by tim-peterson 20
  • Soft-delete just for one user

    Soft-delete just for one user

    When I delete a message as a user, it gets deleted for all the participants. Is there a way to change this so that it just gets deleted for the user who pressed 'delete' or do I have to change the whole table structure for this?

    opened by JuliaSivartsson 19
  • Same Model-DB Issue

    Same Model-DB Issue

    Hey @cmgmyr I'm sorry to bug you again about the same issue, but it seems that even with the Messagable trait correctly spelled within my User model the Laravel-Messenger's models are not being found.

    Like last time, I've got the code inside the MesssagesController's __construct, index, create, and store functions working. But the show and update functions aren't working, because the Thread models aren't being found from the Thread::findOrFail($id) statement (it's coming up as a Class Not Found error).

    I reconstructed and re-uploaded my app (https://github.com/ddink/echo), because I keep hitting that same dead-end. I've got the model files configured correctly, the database is adequately seeded, and I can even query the database for the contents of their tables. The problem is that those queries--like (DB::table('threads')->where('id', $id)->first())--are getting a stdClass object when what I'm trying to get is a Thread object. Because you can't call the Thread model's methods on an object that isn't a Thread object.

    Thanks for all your help.

    opened by ddink 19
  • Messenger Between Scope

    Messenger Between Scope

    Hello! It appears for me, while trying to use default betweenScope located in Thread model, it doesn't work as expected. For example, Thread::between([1,2]) will return all the Threads where users with ids 1 and 2 are participating. Instead, it should return the only chat with users with these ids. Am i the one who is facing this issue? Can you provide some ideas, how to manage this? Thanks in advance!

    bug help wanted in progress hacktoberfest 
    opened by trotsaleksandrov 18
  • vendor:publish

    vendor:publish

    after composer update

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

    it gives nothing to publish ??

    any ideas please ? !

    opened by uusa35 18
  • [Bug] PostgreSQL syntax error

    [Bug] PostgreSQL syntax error

    When using a PostgreSQL database, there are some migrations that fail. This affects the following migrations:

    • add_nullable_to_last_read_in_participants_table.php
    • alter_last_read_in_participants_table.php

    For example, when the first one is run, following error is thrown in the console:

      [Illuminate\Database\QueryException]
      SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "`"
      LINE 1: ALTER TABLE `participants` CHANGE COLUMN `last_read` `last_r...
                          ^ (SQL: ALTER TABLE `participants` CHANGE COLUMN `last_read` `last_read` timestamp NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP;)
    
      [PDOException]
      SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "`"
      LINE 1: ALTER TABLE `participants` CHANGE COLUMN `last_read` `last_r...
                          ^
    

    I am using the latest stable version of both Laravel and this package. The PostgreSQL version I use is 9.4.4

    opened by niknetniko 14
Releases(2.27.0)
  • 2.27.0(Feb 11, 2022)

    What's Changed

    • Support Laravel 9 by @cmgmyr in https://github.com/cmgmyr/laravel-messenger/pull/383

    Full Changelog: https://github.com/cmgmyr/laravel-messenger/compare/2.26.0...2.27.0

    Source code(tar.gz)
    Source code(zip)
  • 2.26.0(Jan 31, 2022)

    What's Changed

    • fix participant soft deletes by @cmgmyr in https://github.com/cmgmyr/laravel-messenger/pull/380

    Full Changelog: https://github.com/cmgmyr/laravel-messenger/compare/2.25.0...2.26.0

    Source code(tar.gz)
    Source code(zip)
  • 2.25.0(Jan 21, 2022)

    What's Changed

    • remove additional types to keep backwards compatibility by @cmgmyr in https://github.com/cmgmyr/laravel-messenger/pull/378

    Full Changelog: https://github.com/cmgmyr/laravel-messenger/compare/2.24.0...2.25.0

    Source code(tar.gz)
    Source code(zip)
  • 2.24.0(Nov 22, 2021)

    What's Changed

    • Fix overzealous type hints, fixes #364, #365 by @cmgmyr
    • PHP 8.1 by @cmgmyr in https://github.com/cmgmyr/laravel-messenger/pull/367

    Full Changelog: https://github.com/cmgmyr/laravel-messenger/compare/2.23...2.24.0

    Source code(tar.gz)
    Source code(zip)
  • 2.23(Nov 17, 2021)

    Added

    • betweenOnly() scope to get private conversations between only passed participants by @AbdullahFaqeir in https://github.com/cmgmyr/laravel-messenger/pull/359

    Updated

    • Test Suite Updates, Use GitHub Actions by @cmgmyr in https://github.com/cmgmyr/laravel-messenger/pull/360

    New Contributors

    • @AbdullahFaqeir made their first contribution in https://github.com/cmgmyr/laravel-messenger/pull/359

    Full Changelog: https://github.com/cmgmyr/laravel-messenger/compare/2.22...2.23

    Source code(tar.gz)
    Source code(zip)
  • 2.22(Jan 27, 2021)

  • 2.21(Sep 16, 2020)

    Added

    • Laravel 8 support
    • PHP 7.4

    Updated

    • Restore onlyTrashed Participants #347
    • PHPUnit

    Removed

    • PHP 7.1

    Upgrading to Laravel 8

    If you'd like to upgrade to Laravel 8's new model directory structure, you'll need to publish the config file, and uncomment the user model option.

    Source code(tar.gz)
    Source code(zip)
  • 2.20(Mar 12, 2020)

  • 2.19(Sep 16, 2019)

  • 2.18(Jun 13, 2019)

    Models/Thread.php

    Updated

    • userUnreadMessages($userId) now checks against the $userId within the query.

    Misc

    • Updates to tests, scrutinizer, travis, and other cleanup
    Source code(tar.gz)
    Source code(zip)
  • 2.17(Mar 10, 2019)

  • 2.16.2(Jun 16, 2018)

  • 2.16.1(Jun 16, 2018)

  • 2.16(Jun 9, 2018)

  • 2.15(Oct 6, 2017)

    • Clean up! Clean up! Clean up! #247 #248 #249 #251 #252 #253 #254
    • Laravel 5.5 package discovery ccec6ac

    Models/Thread.php

    Updated

    • creator() #256 - uses internal cache variable
    • creator() 0a1d2f7 - returns null "User" model

    Models/Message.php

    Added

    • scopeUnreadForUser() #245

    Traits/Messagable.php

    Added

    • unreadMessagesCount() #245
    Source code(tar.gz)
    Source code(zip)
  • 2.14.1(May 8, 2017)

  • 2.14(Apr 8, 2017)

    Models/Message.php

    Added

    • Soft Deletes

    Models/Thread.php

    Added

    • users() relationship

    Example Files

    Updated

    • Replaced html package references with vanilla html and form elements
    • Refactored blade files to better separate functionality

    Removed

    • laravelcollective/html dependancy

    Tests

    • Updated code coverage w/ tests and tags
    • Updated phpunit dependency when available
    • Updated Travis and Scrutinizer configs

    View the changes from 2.13.3 -> 2.14

    Source code(tar.gz)
    Source code(zip)
  • 2.13.3(Feb 9, 2017)

  • 2.13.2(Jan 6, 2017)

  • 2.13.1(Oct 8, 2016)

  • 2.13(Sep 8, 2016)

    Models/Thread.php

    Fixed

    • internal functionality of participantsUserIds(), isUnread(), participantsString(), and userUnreadMessages(). fixes #154, #159

    Traits/Messagable.php

    Fixed

    • internal functionality of threadsWithNewMessages(), and newThreadsCount()

    Examples

    Changed

    • all view files (blade syntax)

    Tests

    Added

    • added additional test coverage to EloquentThreadTest.php and MessagableTraitTest.php
    Source code(tar.gz)
    Source code(zip)
  • 2.12(Aug 11, 2016)

    Models/Thread.php

    Changed

    • refactored the use of lists() to pluck()
    • renamed addParticipants() to addParticipant(). This now can take a single id, an array, or multiple ids as arguments

    Added

    • removeParticipant() which also can take a single id, an array, or multiple ids as arguments

    Traits/Messagable.php

    Changed

    • refactored the use of lists() to pluck()

    Migrations

    • removed 2014_11_10_083449_add_nullable_to_last_read_in_participants_table.php and 2014_11_20_131739_alter_last_read_in_participants_table.php in favor of adjusting 2014_10_28_180224_create_participants_table.php, fixes #57

    Examples

    Changed

    • MessagesController.php
    • unread-count.blade.php
    Source code(tar.gz)
    Source code(zip)
  • 2.11(Jun 24, 2016)

    Models/Thread.php

    Added

    • getBySubject($subjectQuery)
    • userUnreadMessages($userId)
    • userUnreadMessagesCount($userId)

    Traits/Messagable.php

    Changed

    • newMessagesCount() to newThreadsCount()
    Source code(tar.gz)
    Source code(zip)
  • 2.10(Feb 25, 2016)

  • 2.9.1(Jan 29, 2016)

  • 1.8.2(Jan 20, 2016)

  • 2.9(Dec 11, 2015)

  • 2.8.2(Oct 29, 2015)

  • 1.8.1(Oct 29, 2015)

  • 2.8.1(Oct 6, 2015)

Owner
Chris Gmyr
husband & dad, developer, entrepreneur. loves Laravel and coffee. sr dev at @Curology | co-organizer at @trianglephp
Chris Gmyr
Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).

Laravel-FCM Introduction Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud M

Rahul Thapa 2 Oct 16, 2022
A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

Munaf Aqeel Mahdi 1.7k Jan 5, 2023
Talk is a real-time users messaging and chatting system Laravel.

Laravel-Talk Talk is a Laravel 5 based user conversation (inbox) system with realtime messaging. You can easily integrate this package with any Larave

Nahid Bin Azhar 1.5k Dec 30, 2022
Shoutout messaging library for laravel

Laravel Shoutout Messaging Shoutout messaging library for Laravel Laravel PHP framework Shoutout Messaging Requirements PHP 5.6+ Laravel 5.5+ Installa

Dasun Dissanayake 12 Jul 17, 2022
Manage your staff from one place. Featuring Staff leave management 🏖, payslips 💵 generation & emailing, messaging 📨and more 🛠! Built with ❤️ with Laravel

Staff Management System This little buddy can help you manage your staff database! Built with ?? with Laravel #FEATURES 1 Staff management/ database S

Ezekiel Oladejo 45 Jan 3, 2023
User authentication REST API with Laravel (Register, Email verification, Login, Logout, Logged user data, Change password, Reset password)

User Authentication API with Laravel This project is a user authentication REST API application that I developed by using Laravel and MySql. Setup Fir

Yusuf Ziya YILDIRIM 3 Aug 23, 2022
GeoLocation-Package - This package helps you to know the current language of the user, the country from which he is browsing, the currency of his country, and also whether he is using it vpn

GeoLocation in PHP (API) ?? ?? ?? This package helps you to know a lot of information about the current user by his ip address ?? ?? ?? This package h

Abdullah Karam 4 Dec 8, 2022
Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

null 9 Dec 14, 2022
Laravel 2-Step Verification is a package to add 2-Step user authentication to any Laravel project easily.

Laravel 2-Step verification is a package to add 2-Step user authentication to any Laravel project easily. It is configurable and customizable. It uses notifications to send the user an email with a 4-digit verification code. Laravel 2-Step Authentication Verification for Laravel. Can be used in out the box with Laravel's authentication scaffolding or integrated into other projects.

Jeremy Kenedy 204 Dec 23, 2022
Laravel Authentication Log is a package Log user authentication details and send new device notifications.

Laravel Authentication Log is a package which tracks your user's authentication information such as login/logout time, IP, Browser, Location, etc. as well as sends out notifications via mail, slack, or sms for new devices and failed logins.

Anthony Rappa 540 Jan 5, 2023
A Laravel package to help track user onboarding steps.

Onboard A Laravel package to help track user onboarding steps. Installation: Install the package via composer composer require calebporzio/onboard Reg

Caleb Porzio 440 Dec 17, 2022
Laravel Belongs To User Package

If you are creating your own trait to have "belongsTo" User relationship in every model needed, you can also use this package not to define the trait on your own.

Umut Işık 5 Jul 7, 2022
A simple blog app where a user can signup , login, like a post , delete a post , edit a post. The app is built using laravel , tailwind css and postgres

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Nahom_zd 1 Mar 6, 2022
A package to validate email domains in a user registration form

This package allows to define a subset of allowed email domains and validate any user registration form with a custom rule.

H-FARM 56 Jul 19, 2022
This package provides you with a simplistic `php artisan make:user` command

Laracademy Generators Laracademy make:user Command - provides you with a simplistic artisan command to generate users from the console. Author(s): Lar

Laracademy 18 Jan 19, 2019
A package to validate email domains in a user registration form

Laravel Email Domain Rule This package allows to define a subset of allowed email domains and validate any user registration form with a custom rule.

H-FARM Innovation 56 Jul 19, 2022
This package helps you to add user based follow system to your model.

Laravel Follow User follow unfollow system for Laravel. Related projects: Like: overtrue/laravel-like Favorite: overtrue/laravel-favorite Subscribe: o

安正超 1k Dec 31, 2022
This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.

Laravel Verify New Email Laravel supports verifying email addresses out of the box. This package adds support for verifying new email addresses. When

Protone Media 300 Dec 30, 2022
Simple MyBB 1.8 plugin to force moderation of first user post.

MyBB-Moderate-First-Post Simple MyBB 1.8 plugin to force moderation of first user post. Installation: unzip package copy content from "UPLOAD" folder

Sven 3 Jan 2, 2023