PHP code example of vocphone / laravel-matrix-sdk

1. Go to this page and download the library: Download vocphone/laravel-matrix-sdk 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/ */

    

vocphone / laravel-matrix-sdk example snippets


use Vocphone\LaravelMatrixSdk\MatrixClient;

$message = 'My Laravel Test Message';
$roomId = '!someRoom:matrix.org';

app(MatrixClient::class)->sendMessage($message, $roomId);

use Illuminate\Notifications\Notifiable;

class User extends Model
{
    use Notifiable;
    
    public function routeNotificationForMatrix($notification) {
        // If the roomId is null then the message won't attempt to send to matrix
        $roomId = $this->matrix_user_room_id ?? null;
                
        return $roomId;
    }
}

use Illuminate\Notifications\Notification;

class MatrixNotification extends Notification
{
    private $message;
    public function __Construct( string $message ) {
        $this->message = $message;
    }
    
    public function toMatrix( $notifiable ) {
        return $this->message;
    }
}

use Vocphone\LaravelMatrixSdk\MatrixClient;

$matrix = app(MatrixClient::class);

$spaceName = 'My Cool Space';
$public = false; // No way man, it's just for me
$invitees = []; // just me for now
$isSpace = true;
$space = $matrix->createRoom( $spaceName, $public, $invitees, $isSpace);


use Vocphone\LaravelMatrixSdk\MatrixClient;

$inviteUserId = '@new_user:matrix.org';

// get the matrix client instance
$matrix = app(MatrixClient::class);
// make sure we have all the current known information
$matrix->sync();
foreach( $matrix->getRooms() as $room ) {
    if( $room->getIsSpace() ) {
        $room->inviteUser($inviteUserId);
    }
}