musonza / chat Goto Github PK
View Code? Open in Web Editor NEWA Laravel chat package. You can use this package to create a chat/messaging Laravel application.
License: MIT License
A Laravel chat package. You can use this package to create a chat/messaging Laravel application.
License: MIT License
When I run Chat::createConversation() it does create a conversation in a conversations table, but nothing in conversation_user table. Gives an error: "Class name must be a valid object or a string" instead.
First 8 lines from error page...
in Model.php line 939
at Model->belongsToMany(null, 'conversation_user') in Conversation.php line 20
at Conversation->users() in Conversation.php line 65
at Conversation->addParticipants(array('1', '2')) in Conversation.php line 112
at Conversation->start(array('1', '2')) in Chat.php line 33
at Chat->createConversation(array('1', '2')) in Facade.php line 237
at Facade::__callStatic('createConversation', array(array('1', '2'))) in ConversationController.php line 57
at ConversationController->create('2')
I can't find mail on your profile..
Why pagination working only by request? Why I can't use pagination blade?
public function inbox(Request $request) { $user = Auth::user(); //$conversations = Chat::commonConversations($user); //$LastMessages['partcipant'] = $conf->users[1]; $conversations = Chat::conversations()->for($user)->limit(1)->page($request->get('page'))->get(); }
Hello, How I can use default pagination for chat messages, conversations?
Method paginate
not working.
$conversations = Chat::conversations()->for($user)->paginate(10);
Have you been in a call between two users before?
If it is, you need to show the conversation.
Hi,
I'm using your package to add messaging feature to my project. In the messaging feature there is
a user inbox that lists all conversations I had with other users. My problem I want to display the number
of my unread messages per conversation upon viewing the inbox just like when you view your phones inbox where it displays unread messages count per conversation. Is it possible or is there any way to get this done?
Hoping to hear your response.
Thanks!
I did this piece of code
$user = Auth::user();
$mesages = Chat::conversations($user->id);
and it gave me this error:
SQLSTATE[42000]: Syntax error or access violation: 1055 'mydb.messages.id' isn't in GROUP BY (SQL: select
messages.*,
messages.
idas
message_id,
conversation_user.* from
conversation_userinner join
messageson
messages.
conversation_id=
conversation_user.
conversation_idwhere
conversation_user.
user_id= 19 group by
messages.
conversation_idorder by
messages.
id desc)
My user is authenticated and I have some messages/conversations in table as well.
I dont know, but I got errors when I try to migrate table.
so I fix the order, and voila. Its work.
Maybe if you want to help me, you can share the demo/example from this package?
Btw you are awesome, this package is so nice
Hello, How I can remove conversation and all messages in these?
Hello, how I can check if message is read? In controller I send model of message, but how check if message read or not?
Hello,
I'm using your package to create chat feature to my project.
I'm using Laravel 5.5 and I encounter issue when using the package chat facade.
Please check this link to see the error message.
Hope to hear your response/feedback about this issue.
Thanks
Hello, please help me get participant of conversation. Not currently authorized user, are participant conversation.
Is it possible to get the participants in a conversation without the authenticated user in Blade?
How can i order the messages?
Or can i somehow only get the last N messages?
Also i have:
Chat::conversations()->for(\Auth::user())->limit(25)->page(1)->get();
How can i get the other users name in the conversation?
Thanks
I have function:
public function setMessagesSeen(Conversation $conversation, Request $request) {
$v = Validator::make($request->all(), [
'message' => 'required|string|max:4000',
]);
$user = User::find(Auth::id());
$conversations = Chat::conversation($conversation->id);
//$message = Chat::conversations($conversations)->for($user)->getMessages()->where('body', $request->message)->where('user_id', '<>', $user->id);
//$message->markRead();
//var_dump($message); exit;
broadcast(new MessageIsSeen($message));
return response('ok'); }
I have a post request:
methods: {
seenMessage() {
if(this.message.length != 0) {
axios.post('/setMessagesSeen/' + this.convId, {
message: this.message,
})
.then( response => { $('li').removeClass('unread'); })
.catch( response => { console.log(response) } )
}
},
How I can correctly read message for users? I need add/remove class to div in app.js, when message is readed for user. But how check this and mark correctly read message, I need message id?
Hello, I cleared conversation. But how I can check if conversation is cleared? I need add column cleared to mysql?
Hi Musonza,
I am getting an sql error when I used the getMessages method.
my code ::
public function chats()
{
$currentuser = Auth::user();
$conversations = Chat::getConversationBetween($currentuser, 1);
$messages = Chat::conversations()->for($currentuser)->limit(25)->page(1)->get();
//return view('chats',['conversation' => $conversations, 'messages' => $messages]);
//return $messages;
}
it shows the below error ::
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>'$."message_id"' = mc_messages
.id
where mc_messages
.conversation_id
in ' at line 1 (SQL: select notifications
., mc_messages
. from mc_messages
inner join notifications
on notifications
.data
->'$."message_id"' = mc_messages
.id
where mc_messages
.conversation_id
in (1) order by mc_messages
.id
desc)
Please Suggest me something :)
Hey, can you add a new field in conversations table for last message date ? It would be much quicker to sort conversations based on that.
#66
Hello, I have:
Broadcast::channel('mc-chat-conversation.{conversation_id}', function($user) { return $user; });
App.js:
mounted() { Echo.private('mc-chat-conversation.' + this.convId) .listen('MessageWasSent', (e) => { console.log(e); this.chat.message.push(e.message); this.chat.user.push(e.user); this.chat.time.push(this.getTime()); console.log(e); }) .listenForWhisper('typing', (e) => { if(e.name != '') this.typing = 'Набирает сообщение..'; else this.typing = null; }); }
Controller:
broadcast(new MessageWasSent($message))->toOthers();
But event not received data to other user, why??? console.log(e) get empty result.
I think, that event MessageWasSent not know, that need send message to other user. He can only receive a message? Why??
When I run this:
$conversation = Chat::createConversation([$userId, $userId2]);
I get this:
ErrorException in MyController.php line 18:
Non-static method Musonza\Chat\Chat::createConversation() should not be called statically
Can you help me with this? Thank you. I'm new to Laravel.
Hi,
I am using the following to fetch messages:
Chat::conversations($conversation)->for($user)->getMessages($perPage, $page)
But it throws an error.
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>'$."message_id"' = mc_messages
.id
where mc_messages
.conversation_id
= ?' at line 1 (SQL: select count(*) as aggregate from mc_messages
inner join notifications
on notifications
.data
->'$."message_id"' = mc_messages
.id
where mc_messages
.conversation_id
= 1 and mc_messages
.conversation_id
is not null and notifications
.notifiable_id
= 4)
Any help ?
Thanks
Could you please explain how I can start conversation with oneself with existing structure of the table (but before that check if there is already conversation with oneself)? Also before starting conversation with oneself I have already other conversations.
C:\Users\bob\innermessage\blog\vendor\musonza\chat>phpunit
Fatal error: Class 'Musonza\Chat\Tests\TestCase' not found in C:\Users\bob\innermessage\blog\vendor\musonza\chat\tests\Unit\ChatTest.php on line 8
what's wrong one my testing running
hello.
thank you for this package.
I have some users in my web application and I want to implement direct messaging to each other.
could I use this package? how to use this package for this purpose?
To list the messages of the user, to get information of the person who is not himself
In the meantime, the best class
foreach(Chat::conversation($user->conversation_id)->users as $kullanici){
if($kullanici->id !== $userId){
$us = $kullanici;
}
}
public function conversations($userId)
{
$c = ConversationUser::join('messages', 'messages.conversation_id', '=', 'conversation_user.conversation_id')
->where('conversation_user.user_id', $userId)
->groupBy('messages.conversation_id')
->orderBy('messages.id', 'DESC')
->get(['messages.*', 'messages.id as message_id', 'conversation_user.*']);
$messages = [];
foreach ($c as $user) {
foreach(Chat::conversation($user->conversation_id)->users as $kullanici){
if($kullanici->id !== $userId){
$us = $kullanici;
}
}
$recent_message = $user->conversation->messages()->orderBy('id', 'desc')->first()->toArray();
$notification = MessageNotification::where('user_id', $userId)
->where('message_id', $user->id)
->get(['message_notification.id',
'message_notification.is_seen',
'message_notification.is_sender']
);
$messages[] = array_merge(
$recent_message, ['notification' => $notification,'users'=>$us]
);
}
return $messages;
}
for example if I'm in a conversation and last message id is 10 then there are new messages came and how i get the message(s) greater than 10.
and also there are no any function to get a one single message, and Message send function doesn't return the message that sent so i have to recall a function to get the last message.
Hello, How I can attach file to conversation in message?
I am facing this error !!
FatalErrorException in ConversationController.php line 14:
Class 'App\Http\Controllers\Chat' not found
How can i fix that ?
Hello, How I can integrate this package with vue and pusher?
Hi,
I installed this bundle in My Laravel project but I can’t stop having this error:
SQLSTATE[42000]:
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>'$."message_id"' = mc_messages
.id
where mc_messages
.conversation_id
in ' at line 1 (SQL: select notifications
., mc_messages
. from mc_messages
inner join notifications
on notifications
.data
->'$."message_id"' = mc_messages
.id
where mc_messages
.conversation_id
in (16, 31, 7, 35, 36) order by mc_messages
.id
desc) `
Trying to understand the error makes me understand that it is about the version of MYSQL. I was actually using version 5.6.38
I used a different database with MyQL 5.7.18 and everything worked fine.
How could we address this issue? The problem is that i even tried to debug the code in other to find where the problem occurs and try to fix it but it seems really complicated. By the way I cannot just comment the package code in my local version cause it wouldn’t work on production anyway.
I should notice that the MYSQL requirements are not specified in the package documentation.
My Laravel version is 5.3.31
The issue is that the messages table is created before the conversations table and the message table institutes foreign key restraints on the conversations table (that doesn't exist yet!).
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1005 Can't create table chat
.#sql-644_132
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table messages
add constraint messages_conversation_id_foreign
foreign key (conversation_id
) references conversations
(id
))
[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table chat
.#sql-644_132
(errno: 150 "Foreign key constraint is incorrectly formed")
On a clean install, the trick to getting the migration to work properly is to rename the messages table such that it'll be run after the conversation table is created.
I renamed mine to:
2016_03_05_060940_create_messages_table.php
After cleaning up the database I reran the migration without issues.
Alternatively, you could put the foreign key restraint code in the Conversations migration, but make sure it references the proper table.
Looking forward to playing with your Chat.
Hi there. How can I overwrite Chat::send method? I need to attach a file id to message.
Thanks.
Hello my friend! I have a question, if on site we have 2 users (admins), How I can create bot, which will respond to users by name these admins?
I did follow your steps but my migration and config files didn't create in folder.
Do you have any plans to integrate Pusher (or socket.io, ...) for real-time chat?
How do i get conversations list from a user order by last updated, Chat::commonConversations
doesn't return eloquent instance. And is there a way to get No. of unread messages for a user ? or do we have do it by manually ?
Are you gonna implement broadcasting ?
I keep User model in CustomName\Models\User namespace. Is there easy way I can change the settings or should I check each file and change it manually?
How do I check if conversation already exists between two users? Method getConversationBetweenUsers() gives you one only if there is one, otherwise throws error "Undefined offset: 0", instead of null or false...
Hello,
I am building a shopping site which can offer a function customers can make conversation with staff from the company, One more requirement is attachment function
Hi
Im getting the fol;owing error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>'$."message_id"' = mc_messages
.id
where mc_messages
.conversation_id
= ?' at line 1 (SQL: select count(*) as aggregate from mc_messages
inner join notifications
on notifications
.data
->'$."message_id"' = mc_messages
.id
where mc_messages
.conversation_id
= 2 and mc_messages
.conversation_id
is not null and notifications
.notifiable_id
= 1)
Any tips fixing this?
Thanks
Hello, how I can get unread messages?
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>'$."message_id"' = mc_messages
.id
where mc_messages
.conversation_id
in ' at line 1 (SQL: select notifications
., mc_messages
. from mc_messages
inner join notifications
on notifications
.data
->'$."message_id"' = mc_messages
.id
where mc_messages
.conversation_id
in (1) order by mc_messages
.id
desc)
PHP: 7.0
MySQL: 5.6
Using Chat::messages() I get all the messages in a conversation, but they all come in under same sender or recipient (depending on which ID you put as first parameter) no matter if I am a sender or recipient.
Even if I'm a sender but using recipients ID in a function the message sender shows up as a recipient.
Is there a way to distinguish which message belongs to which user?
Would it be possible for you to add a method to get ids and usernames of all open/started conversations for a logged in user? Something like getAllOpenChatsUsers(). Let's say I want to show just a list of all users I have started a conversation with (or they started with me)
I get a non object on conversations, when click on conversation with people. Why??
Chat::conversations($conversation)->for($user)->clear();
This remove only my messages from conversation.
When I go to conversation with participant, I get error:
Trying to get property of non-object
In my blade
@foreach($conversations as $key => $confs)
<tr onclick="window.location.href = '{{ route('chatconv', $confs->last_message->conversation_id) }}?last=1'">
<td><img class="user-avatar" src="{{ $recipient[$key]->avatar }}" alt="{{ $confs->last_message->sender->name }}"> <span class="name">{{ $recipient[$key]->name }}
@if(Helper::getOnlineUser($recipient[$key]->id))
<i data-toggle="tooltip" title="Online" class="material-icons online">fiber_manual_record</i>
@else
<i data-toggle="tooltip" title="Offline" class="material-icons offline">fiber_manual_record</i>
@endif
</span></td>
<td>{{ $confs->last_message->body }}</td>
<td>{{ $confs->last_message->updated_at->diffForHumans() }}</td>
</tr>
@endforeach
Controller:
public function inbox(Request $request) {
$user = $this->user;
//$conversations = Chat::commonConversations($user);
//$LastMessages['partcipant'] = $conf->users[1];
$conversations = Chat::conversations()->for($user)->limit(15)->page($request->page)->get();
//dd($conversations); exit;
//dd($conversations);
$recipient = [];
//dd($conversations);
foreach($conversations as $conf) {
$recipient[] = $conf->users()->where('user_id', '<>', $user->id)->first();
}
//dd($recipient);
return view('inbox.index', compact('conversations', 'recipient'));
}
I need remove dialog for user. But how I can check this?
I get messages in dialog with:
$messages = Chat::conversations($conversation)->for($user)->getMessages($limit, $request->page);
Hi, bro
I try to use your chat and i've a little problem.
JSON_EXTRACT function error
I know its because i'm using a mysql version without that function, but, have a solution about it?
I can't change the version of mysql, my production are in a shared host.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.