Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Chat Bundle Laravel Package

btba/chat-bundle

Symfony bundle providing a simple chat service with configurable refresh interval and Doctrine entities for authors and messages. Install via Composer, register the bundle, add YAML config and routes, and extend base models to persist chat data.

View on GitHub
Deep Wiki
Context7

POGODEV

Welcome to the chat bundle project !

Build Status Maintainability Test Coverage License: MIT

This project aim to offer a simple chat service to any symfony application.

installation

As this project is very new, we decided not to add a receipe on Symfony Flex at the moment so the configuration must be performed manually.

register

First install the dependencies by running this comand in your repository

composer require btba/chat-bundle

and register the bundle

// config/bundles.php

return [
    //your bundles
    Btba\ChatBundle\BtbaChatBundle::class => ['all' => true]
];

config

then in your app directory add a config file. The following parameters are mandatory:

# config/packages/btba_chat.yaml

btba_chat:
    update_interval: 1000
    message_class: App\Entity\ChatMessage
    author_class: App\Entity\User

update_interval refers to the time between two refresh of the chat
message_class refers to the ORM class that host the messages (Doctrine supported)
author_class refers to the ORM class that host the auhors (Doctrine supported)

Then register the bundle routes and change the prefix according to your needs

# config/routes/btba_chat.yaml

btba_chat:
    resource: '@BtbaChatBundle/Resources/config/routes.yaml'
    prefix: /chat-bundle/

database

In order to save authors and messages in your database you need to create at least two classes that extends the bundle model as such:

// App\Entity\User

/**
 * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
 */
class User extends BaseAuthor implements UserInterface
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=180, unique=true)
     */
    protected $username;
    
     /**
     * @ORM\OneToMany(targetEntity="App\Entity\ChatMessage", mappedBy="author", cascade={"persist"}, orphanRemoval=true)
     */
    private $messages;
// App\Entity\ChatMesssage

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Btba\ChatBundle\Model\BaseChatMessage;

/**
 * @ORM\Entity(repositoryClass="App\Repository\ChatMessageRepository")
 */
class ChatMessage extends BaseChatMessage
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    protected $content;

    /**
     * @ORM\Column(type="datetime")
     */
    protected $date;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="messages", cascade={"persist"})
     * @ORM\JoinColumn(nullable=false)
     */
    protected $author;

}

and in the message_class repository add the following trait:

// src/Repository/ChatMessageRepository.php

namespace App\Repository;

use Btba\ChatBundle\Query\MessageQuery;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;

class ChatMessageRepository extends ServiceEntityRepository
{
    use MessageQuery;
    
    //your code...
}

configuration is over you are good to go !

usage

To use this bundle, you need to add several component to your views.

If you're using encore, add the following assets to you're app.css file

@import '../../vendor/btba/chat-bundle/assets/css/chat.css';

and app.js file

import * as chat from '../../vendor/btba/chat-bundle/assets/js/chat';

//functions for the chat window management 
$(function(){
    $("#chevron").click(function(e) {
        chat.changeChevron(e.target);
    });
    
    $("#chat-submit").click(function(e) {
        chat.submitChat(e);
    });
});

in your view you now just have to render the following controller:

{{ render(controller('Btba\\ChatBundle\\Controller\\ChatController::show')) }}

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
yandex/translate-api
voku/simple_html_dom
league/flysystem-vfs
bkwld/upchuck
filament/spatie-laravel-tags-plugin
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php