PHP code example of coliving / talk

1. Go to this page and download the library: Download coliving/talk 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/ */

    

coliving / talk example snippets


Nahid\Talk\TalkServiceProvider::class,

'Talk'      => Nahid\Talk\Facades\Talk::class,

return [
    'user' => [
        'model' => 'App\User'
    ],
    'broadcast' => [
        'enable' => false,
        'app_name' => 'your-app-name',
        'pusher' => [
            'app_id'        => '',
            'app_key'       => '',
            'app_secret'    => '',
            'options' => [
                 'cluster' => 'ap1',
                 'encrypted' => true
            ]
        ]
    ]
];

 'talk'  =>  \Nahid\Talk\Middleware\TalkMiddleware::class,
 

 $this->middleware('talk');
 

Talk::setAuthUserId(auth()->user()->id);

Talk::user(auth()->user()->id)->anyMethodHere();

void setAuthUserId($userid)

function __construct()
{
    Talk::setAuthUserId(auth()->user()->id);
}

object user($id)

$inboxes = Talk::user(auth()->user()->id)->threads();
return view('messages.threads', compact('inboxes'));

int|false isConversationExists($userid)

if ($conversationId = Talk::isConversationExists($userId)) {
    Talk::sendMessage($conversationId, $message);
}

boolean isAuthenticUser($conversationId, $userId)

if (Talk::isAuthenticUser($conversationId, $userId)) {
    Talk::sendMessage($conversationId, $message);
}

object|false sendMessage($conversationId, $message)

    $message = Talk::sendMessage($conversationId, $message);
    if ($message) {
        return response()->json(['status'=>'success', 'data'=>$message], 200);
   }

object|false sendMessageByUserId($userId, $message)

array getInbox([$order = 'desc'[,$offset = 0[, $take = 20]]])

// controller method
$inboxes = Talk::getInbox();
return view('message.threads', compact('inboxes');

object getInboxAll([$order = 'desc'[,$offset = 0[, $take = 20]]])

array threads([$order = 'desc'[,$offset = 0[, $take = 20]]])

array threadsAll([$order = 'desc'[,$offset = 0[, $take = 20]]])

array getConversationsById($conversationId[, $offset = 0[, $take = 20]])

// controller method
$conversations = Talk::getConversationsById($conversationId);
$messages = $conversations->messages;
$withUser = $conversations->withUser;

return view('messages.conversations', compact('messages', 'withUser'));

array getConversationsAllById($conversationId[, $offset = 0[, $take = 20]])

object getConversationsByUserId($receiverId [, $offset = 0[, $take = 20]])

array getConversationsAllByUserId($receiverId[, $offset = 0[, $take = 20]])

array messages($conversationId[, $offset = 0[, $take = 20]])

array messagesAll($conversationId[, $offset = 0[, $take = 20]])

array messagesByUserId($receiverId[, $offset = 0[, $take = 20]])

array messagesAllByUserId($receiverId[, $offset = 0[, $take = 20]])

array readMessage($messageId)

object getReceiverInfo($conversationId)

boolean makeSeen($messageId)

boolean deleteMessage($messageId)

boolean deleteForever($messageId)

boolean deleteConversations($conversationId)

return [
    'user' => [
        'model' => 'App\User'
    ],
    'broadcast' => [
        'enable' => false,
        'app_name' => 'your-app-name',
        'pusher' => [
            'app_id'        => '',
            'app_key'       => '',
            'app_secret'    => ''
        ]
    ]
];

php artisan vendor:publish --provider="Nahid\Talk\TalkServiceProvider"
shell
php artisan migrate
html
<!-- messages/threads.blade.php -->
<ul>
    @foreach($inboxes as $inbox)
        <li>
            <h2>{{$inbox->withUser->name}}</h2>
            <p>{{$inbox->thread->message}}</p>
            <span>{{$inbox->thread->humans_time}}</span>
        </li>
    @endforeach
</ul>
html
<!-- messages/conversations.blade.php -->
<div class="message-container">
    <h2>Chat with {{$withUser->name}}</h2>
    @foreach($messages as $msg)
     <div class="message">
        <h4>{{$msg->sender->name}}</h4>
        <span>{{$msg->humans_time}}</span>
        <p>
            {{$msg->message}}
       </p>
    </div>
    @endforeach
</div>