PHP code example of thundev / matrix-notification-channel

1. Go to this page and download the library: Download thundev/matrix-notification-channel 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/ */

    

thundev / matrix-notification-channel example snippets




namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Notifications\Notification;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * @param  Notification  $notification
     */
    public function routeNotificationForMatrix($notification): string
    {
        return 'your_room_id';
    }
}



namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Thundev\MatrixNotificationChannel\Contracts\MatrixNotificationContract;
use Thundev\MatrixNotificationChannel\Message\MatrixMessage;

class InvoiceCreatedNotification extends Notification implements MatrixNotificationContract
{
    use Queueable;
    
    public function via(mixed $notifiable): array
    {
        return ['matrix'];
    }

    public function toMatrix(mixed $notifiable): MatrixMessage
    {
        return (new MatrixMessage())->message('My awesome message!');
    }
}

(new User())->notify(new InvoiceCreatedNotification());
bash
php artisan vendor:publish --tag="matrix-config"