Download the PHP package benwilkins/yak without Composer
On this page you can find all versions of the php package benwilkins/yak. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yak
Yak for Laravel
A robust messaging system built for the Laravel framework. Create conversations between many users or one-on-one.
Built for Laravel 5.4 and up.
Installation
Start sending messages in just a few easy steps:
1. Add to Laravel via Composer
composer require benwilkins/yak
2. Register the Service Provider and Facade
In config/app.php
, add the following:
3. Publish the config
php artisan vendor:publish
4. Run the migrations
php artisan migrate
5. Add the trait to your User model
Usage
Conversations
A conversation can exist between two or more participants. Participants can be added and removed easily through some methods that are included on the Conversation model.
Starting or finding a conversation
Yak includes a method to easily find or create a conversation between participants:
Adding/removing participants
You can easily add or remove participants from a conversation. If a conversation only has two participants, an exception will be thrown if you try to remove one of them.
Messages
Sending a message
Yak also includes a way to send a message to one or more users. This method will either find or create a conversation, and add the message to it automagically in one easy step.
Conversation States
A conversation state will determine if the conversation has unread messages for a given user. The conversation model will include a state_for_current_user
attribute.
Participants (Users via Messageable trait)
By adding the Messageable
trait to your User model, you can get all conversations and messages for a given user.
You can also get a "conversation list" for a user, which will return all unread conversations at the top of the list, followed by the next eight read conversations. You may override the number of read conversations to append to the the list.
Events
ConversationStarted
When using the Yak facade to start a conversation, a Benwilkins\Yak\Events\ConversationStarted
event will be fired.
MessageSent
When a new message is created, a Benwilkins\Yak\Events\MessageSent
event will be fired.
YakConversationParticipantAdded
When adding a participant(s) to a conversation via the addParticipants
method on the Conversation model, a Benwilkins\Yak\Events\ConversationParticipantAdded
event will be fired.
YakConversationParticipantRemoved
When removing a participant(s) to a conversation via the removeParticipants
method on the Conversation model, a Benwilkins\Yak\Events\ConversationParticipantRemoved
event will be fired.
Contracts
It is possible to extend all the models in the package, and even the Yak facade. To do so, simply create and register new service provider that binds the model contracts to the models you want to use.
Note: I highly recommend just extending the current models. There are boot methods and model events contained in there that are important to the application.
Example
And in config/app.php
: