vojislavd / laravel-messages
Laravel messages system
Requires
- php: ^8.0
Requires (Dev)
- livewire/livewire: ^2.10
- orchestra/testbench: ^7.1
- phpunit/phpunit: ^9.5
README
This package adds messages system to Laravel application based on TALL stack (Tailwind CSS, Alpine.js, Laravel, Livewire).
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.