Git Product home page Git Product logo

chat's Introduction

Build Status Monthly Installs

Chat

This package allows you to add a chat system to your Laravel 5 application

Installation

From the command line, run:

composer require musonza/chat

Add the service provider to your config\app.php the providers array

Musonza\Chat\ChatServiceProvider

You can use the facade for shorter code. Add this to your aliases:

'Chat' => Musonza\Chat\Facades\ChatFacade::class to your `config\app.php`

The class is bound to the ioC as chat

$chat = App::make('chat');

Publish the assets:

php artisan vendor:publish

This will publish database migrations and a configuration file chat.php in the Laravel config folder.

Usage

By default the package assumes you have a User model in the App namespace. However, you can update the user model in 'chat.php' published in the config folder.

Creating a conversation

$conversation = Chat::createConversation([$userId, $userId2,...]); //takes an array of user ids

Get a conversation given a conversation_id

$conversation = Chat::conversation($conversation_id);

Send a message

Chat::send($conversation->id, 'Hello', $userId); //$userId sending a message to created conversation

Mark message as read

Chat::messageRead($messageId, $userId); //$userId marks the mesage as read

Mark whole conversation as read

Chat::conversationRead($conversation->id, $userId);

Delete a message

Chat::trash($messageId, $userId);

Clear a conversation

Chat::clear($conversation->id, $userId);

Get conversation for two users

Chat::getConversationBetweenUsers($userId, $userId2);

Remove user(s) from conversation

Chat::removeParticipants($conversation->id, $usersId); //removing one user
Chat::removeParticipants($conversation->id, [$usersId, $userId2]); //removing multiple users

Add user(s) to a conversation

Chat::addParticipants($conversation->id, $userId3); //add one user
Chat::addParticipants($conversation->id, [$userId3, $userId4]); //add multiple users

Get messages in a conversation

Chat::messages($userId, $conversation->id, $perPage, $page);

Get recent messages

$mesages = Chat::conversations($userId);

Get users in a conversation

$users = $conversation->users;

chat's People

Contributors

musonza avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.