vojislavd/laravel-messages

Laravel messages system

v0.1.0 2022-03-17 23:28 UTC

This package is auto-updated.

Last update: 2024-06-08 10:50:05 UTC


README

This package adds messages system to Laravel application based on TALL stack (Tailwind CSS, Alpine.js, Laravel, Livewire).

158830293-54bb73e1-acae-44f8-a52a-d2b0149865e4.gif

Requirments

This package is compatible with Laravel Jetstream package for Livewire stack. If you have it installed and working there are no further steps required.

If you don't have Laravel Jetstream, you need to have some sort of authentication because the package use Laravels Authenticatable class to get authenticated user. Also, you need to have already installed and working Tailwind CSS, Alpine.js and Livewire.

Installation

You can install the package via composer:

composer require vojislavd/laravel-messages

After that you need to publish migrations and config files:

php artisan vendor:publish --tag="laravel-messages-migrations"
php artisan vendor:publish --tag="laravel-messages-config"

Run migration:

php artisan migrate

In your User model class add Messagable trait:

// App\Models\User.php

use VojislavD\LaravelMessages\Traits\Messagable;

class User extends Authenticatable
{
    use Messagable;

    ...
}

In tailwind.config.js file add blade files from this package:

module.exports = {
    content: [
        './vendor/vojislavd/laravel-messages/**/*.blade.php', // <-- Add this line
    ],

    theme: {},

    plugins: [],
};

Install dependencies and run build process:

npm install && npm run dev

Usage

Include the component to your HTML page:

@livewire('inbox')

Auto Refresh Messages

In config file config\messages.php you can configure component to automatically refresh and to get new messages, also you can configure refresh interval.

'update' => [
    'auto' => true,
    'interval' => 750 // milliseconds
],

By default, auto refresh option is disabled.

Filter Forbidden Words

The Component has a basic filter for forbidden words. In config file you can configure words to be filtered with option to filter exact words or contain text.

'validation' => [
    'filter' => [
        'exact' => ['exact', 'forbidden', 'words'],
        'contain' => ['contain', 'forbidden', 'words'],
    ],
],

Change Style Of Component

If you want to change style of component, you need to publish view file.

php artisan vendor:publish --tag="laravel-messages-views"

Testing

Run tests with:

composer test

Credits

License

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