PHP code example of metafroliclabs / laravel-chat

1. Go to this page and download the library: Download metafroliclabs/laravel-chat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

metafroliclabs / laravel-chat example snippets


'type' => 'standard',

'features' => [
    'reactions' => true,
    'views' => false
],

'pagination' => true,

'message' => [
    'enable_activity' =>  false,
]

'user' => [
    'name_cols' => ['first_name', 'last_name'], // Columns to build full name
    'image_col' => 'avatar',                    // Column for profile picture
    'enable_image_url' => true,                 // If true, image will be URL
]

'rate_limits' => [
    'chat_creation_per_minute' => 20, // Max 20 chats per user per minute
    'messages_per_minute' => 40      // Max 40 messages per user per minute
],

public MessageSent(Chat $chat, array $messages, User $sender, array $receiver)

namespace App\Listeners;

use Metafroliclabs\LaravelChat\Events\MessageSent;
use Illuminate\Contracts\Queue\ShouldQueue;

class HandleMessageSent implements ShouldQueue
{
    public function handle(MessageSent $event)
    {
        $chat = $event->chat;
        $messages = $event->messages;
        $sender = $event->sender;
        $receivers = $event->receivers;

        // Example: Send push notifications or log activity
    }
}

protected $listen = [
    Metafroliclabs\LaravelChat\Events\MessageSent::class => [
        App\Listeners\HandleMessageSent::class,
    ],
];
bash
php artisan chat:install
bash
php artisan vendor:publish --tag=chat-config
bash
php artisan migrate
bash
php artisan storage:link
bash
php artisan make:listener HandleMessageSent
bash
php artisan event:cache