finller/laravel-conversations

Attach chat to any model

v0.5.2 2024-05-12 21:57 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package the basic architecture of a chat between multiple users.

Installation

You can install the package via composer:

composer require finller/laravel-conversations

You can publish and run the migrations with:

php artisan vendor:publish --tag="conversations-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="conversations-config"

This is the contents of the published config file:

return [

    /**
     * The Model used with the user_id and owner_id
     */
    'model_user' => User::class,

    'model_message' => Message::class,

    'model_conversation' => Conversation::class,

    /**
     * When a User is deleted, his messages will be deleted
     */
    'cascade_user_delete_to_messages' => false,

    /**
     * When a User is deleted, his messages will be deleted
     */
    'cascade_conversation_delete_to_messages' => false,

    /**
     * When the parent of a conversation is deleted, the conversation is deleted
     */
    'cascade_conversationable_delete_to_conversation' => false,
];

Usage

1. Create the conversation

$conversation = new Conversation();

$conversation->conversationable()->associate($mission); // optional

$conversation->save();

$conversation->users()->sync($usersIds);

2. Save messages in the conversation

$message = new Message([
    'content' => "My message",
]);

$message->user()->associate($this->user);

$this->conversation->messages()->save($message);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.