1. Go to this page and download the library: Download rhishi-kesh/quick-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/ */
public function initials(): string
{
return Str::of($this->name)
->explode(' ')
->take(2)
->map(fn($word) => Str::substr($word, 0, 1))
->implode('');
}
// Messages sent by this user
public function sentMessages()
{
return $this->hasMany(Message::class, 'sender_id');
}
// Messages received by this user (for direct/private chats only)
public function receivedMessages()
{
return $this->hasMany(Message::class, 'receiver_id');
}
// Conversations where user is a participant
public function participants()
{
return $this->morphMany(Participant::class, 'participant');
}
// Conversations where user is a participant (through Participant model)
public function conversations()
{
return $this->hasManyThrough(
Conversation::class,
Participant::class,
'participant_id', // Foreign key on Participant table
'id', // Local key on Conversation table
'id', // Local key on User table
'conversation_id' // Foreign key on Participant table
)->where('participant_type', self::class);
}
// Message reactions made by this user
public function messageReactions()
{
return $this->hasMany(MessageReaction::class);
}
// Read/delivery status records
public function messageStatuses()
{
return $this->hasMany(MessageStatus::class);
}
// Firebase tokens for push notifications
public function firebaseTokens()
{
return $this->hasOne(FirebaseToken::class);
}