PHP code example of benwilkins / yak

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

    

benwilkins / yak example snippets


'providers' => [
    // ...
    Benwilkins\Yak\YakServiceProvider::class,
    // ...
],

'aliases' => [
    // ...
    'Yak' => Benwilkins\Yak\Facades\Yak::class,
    // ...
],



namespace App;

use Benwilkins\Yak\Traits\Messageable;

class User extends Authenticatable
{
    use Notifiable, Messageable;
    // ...

// One easy method
$conversation = Yak::startOrFindConversation([$userId1, $userId2, ...]);

// Find a conversation manually
$conversation = Yak::findConversation([$userId1, $userId2, ...]);

// Adding many participants
$conversation->addParticipants([$userId1, $userId2, ...]);

// Adding one participant
$conversation->addParticipants($userId);

// Removing many participants
$conversation->removeParticipants([$userId1, $userId2, ...]);

// Removing one participant
$conversation->removeParticipants($userId);

$conversation = Yak::sendMessageToParticipants([$userId1, $userId2, ...]);

// Get all conversations for the user
$conversations = $user->conversations;

// Get all messages sent by the user
$messages = $user->messages;

// Get a count of unread messages
$unreadCount = $user->unreadMessageCount();

// Get all conversations containing unread messages
$unreadConversations = $user->unreadConversations();

$conversations = $user->conversationList($readCount = 8);

 

namespace App\Providers;

// App\MyConversation will extend Benwilkins\Yak\Models\Conversation
// and implement Benwilkins\Yak\Contracts\Models\Conversation
use App\MyConversation;  
use Benwilkins\Yak\Contracts\Models\Conversation as ConversationContract;
use Illuminate\Support\ServiceProvider;

class YakServiceProvider extends ServiceProvider {
	
	public function register()
	{
		$this->app->bind(
			ConversationContract::class,
			MyConversation::class
		);
	}
}

'providers' => [
	...
	Benwilkins\Yak\YakServiceProvider::class,
	App\Providers\YakServiceProvider::class, // Make sure this one comes after the one before it.
	...
],