From a37e90da865fd3a72477675ff2c9a27d51333492 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 26 Feb 2018 16:36:25 +0000 Subject: [PATCH] Updating the docs --- _docs/2-Configuration.md | 11 +- _docs/3-Usage.md | 387 +-------------------------------------- 2 files changed, 13 insertions(+), 385 deletions(-) diff --git a/_docs/2-Configuration.md b/_docs/2-Configuration.md index 50c62c8..c99de97 100644 --- a/_docs/2-Configuration.md +++ b/_docs/2-Configuration.md @@ -20,7 +20,9 @@ return [ */ 'database' => [ - 'connection' => config('database.default'), + 'connection' => env('DB_CONNECTION', 'mysql'), + + 'prefix' => null, ], /* ----------------------------------------------------------------- @@ -31,6 +33,7 @@ return [ 'users' => [ 'table' => 'users', 'model' => App\User::class, + 'morph' => 'participable', ], 'discussions' => [ @@ -38,9 +41,9 @@ return [ 'model' => Arcanedev\LaravelMessenger\Models\Discussion::class ], - 'participants' => [ - 'table' => 'participants', - 'model' => Arcanedev\LaravelMessenger\Models\Participant::class, + 'participations' => [ + 'table' => 'participations', + 'model' => Arcanedev\LaravelMessenger\Models\Participation::class, ], 'messages' => [ diff --git a/_docs/3-Usage.md b/_docs/3-Usage.md index 4a03c2d..be98a0b 100644 --- a/_docs/3-Usage.md +++ b/_docs/3-Usage.md @@ -31,391 +31,16 @@ class User extends Authenticatable { ### API +Try to check the tests folder for more details about the usage: [click here](https://github.com/ARCANEDEV/LaravelMessenger/blob/master/tests) + #### Discussions -```php - - * - * @property int id - * @property string subject - * @property \Carbon\Carbon created_at - * @property \Carbon\Carbon updated_at - * @property \Carbon\Carbon deleted_at - * - * @property \Illuminate\Database\Eloquent\Model creator - * @property \Illuminate\Database\Eloquent\Collection messages - * @property \Illuminate\Database\Eloquent\Collection participants - * @property \Arcanedev\LaravelMessenger\Models\Message latest_message - * - * @method static \Illuminate\Database\Eloquent\Builder subject(string $subject, bool $strict) - * @method static \Illuminate\Database\Eloquent\Builder between(array $usersIds) - * @method static \Illuminate\Database\Eloquent\Builder forUser(int $userId) - * @method static \Illuminate\Database\Eloquent\Builder forUserWithNewMessages(int $userId) - */ -interface Discussion -{ - /* ------------------------------------------------------------------------------------------------ - | Relationships - | ------------------------------------------------------------------------------------------------ - */ - /** - * Participants relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function participants(); - - /** - * Messages relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function messages(); - - /** - * Get the user that created the first message. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function creator(); - - /* ------------------------------------------------------------------------------------------------ - | Scopes - | ------------------------------------------------------------------------------------------------ - */ - /** - * Scope discussions that the user is associated with. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param int $userId - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeForUser(Builder $query, $userId); - - /** - * Scope discussions with new messages that the user is associated with. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param int $userId - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeForUserWithNewMessages(Builder $query, $userId); - - /** - * Scope discussions between given user ids. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param array $userIds - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeBetween(Builder $query, array $userIds); - - /** - * Scope the query by the subject. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param string $subject - * @param bool $strict - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeSubject(Builder $query, $subject, $strict = false); - - /* ------------------------------------------------------------------------------------------------ - | Getters & Setters - | ------------------------------------------------------------------------------------------------ - */ - /** - * Get the latest_message attribute. - * - * @return \Arcanedev\LaravelMessenger\Models\Message - */ - public function getLatestMessageAttribute(); - - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ - */ - /** - * Returns all of the latest discussions by `updated_at` date. - * - * @return \Illuminate\Database\Eloquent\Collection - */ - public static function getLatest(); - - /** - * Returns all discussions by subject. - * - * @param string $subject - * @param bool $strict - * - * @return \Illuminate\Database\Eloquent\Collection - */ - public static function getBySubject($subject, $strict = false); - - /** - * Returns an array of user ids that are associated with the discussion. - * - * @param int|null $userId - * - * @return \Illuminate\Support\Collection - */ - public function participantsUserIds($userId = null); - - /** - * Add a user to discussion as a participant. - * - * @param int $userId - * - * @return \Arcanedev\LaravelMessenger\Models\Participant - */ - public function addParticipant($userId); - - /** - * Add users to discussion as participants. - * - * @param array $userIds - * - * @return \Illuminate\Database\Eloquent\Collection - */ - public function addParticipants(array $userIds); - - /** - * Remove a participant from discussion. - * - * @param int $userId - * @param bool $reload - * - * @return int - */ - public function removeParticipant($userId, $reload = true); - - /** - * Remove participants from discussion. - * - * @param array $userIds - * @param bool $reload - * - * @return int - */ - public function removeParticipants(array $userIds, $reload = true); - - /** - * Mark a discussion as read for a user. - * - * @param int $userId - * - * @return bool|int - */ - public function markAsRead($userId); - - /** - * See if the current thread is unread by the user. - * - * @param int $userId - * - * @return bool - */ - public function isUnread($userId); - - /** - * Finds the participant record from a user id. - * - * @param int $userId - * - * @return \Arcanedev\LaravelMessenger\Models\Participant - */ - public function getParticipantByUserId($userId); - - /** - * Get the trashed participants. - * - * @return \Illuminate\Database\Eloquent\Collection - */ - public function getTrashedParticipants(); +Contract/Interface: [Link](https://github.com/ARCANEDEV/LaravelMessenger/blob/master/src/Contracts/Discussion.php) - /** - * Restores all participants within a discussion. - * - * @param bool $reload - * - * @return int - */ - public function restoreAllParticipants($reload = true); +#### Participation - /** - * Generates a participant information as a string. - * - * @param int|null $ignoredUserId - * @param \Closure|null $callback - * @param string $glue - * - * @return string - */ - public function participantsString($ignoredUserId = null, $callback = null, $glue = ', '); - - /** - * Checks to see if a user is a current participant of the discussion. - * - * @param int $userId - * - * @return bool - */ - public function hasParticipant($userId); - - /** - * Returns array of unread messages in discussion for given user. - * - * @param int $userId - * - * @return \Illuminate\Support\Collection - */ - public function userUnreadMessages($userId); -} -``` - -#### Participants - -```php - - * - * @property int id - * @property int discussion_id - * @property \Arcanedev\LaravelMessenger\Models\Discussion discussion - * @property int user_id - * @property \Illuminate\Database\Eloquent\Model user - * @property \Carbon\Carbon last_read - * @property \Carbon\Carbon created_at - * @property \Carbon\Carbon updated_at - * @property \Carbon\Carbon deleted_at - */ -interface Participant -{ - /* ------------------------------------------------------------------------------------------------ - | Relationships - | ------------------------------------------------------------------------------------------------ - */ - /** - * Discussion relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function discussion(); - - /** - * User relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function user(); - - /* ------------------------------------------------------------------------------------------------ - | Getters & Setters - | ------------------------------------------------------------------------------------------------ - */ - /** - * Get the participant string info. - * - * @return string - */ - public function stringInfo(); - - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ - */ - /** - * Restore a soft-deleted model instance. - * - * @return bool|null - */ - public function restore(); -} -``` +Contract/Interface: [Link](https://github.com/ARCANEDEV/LaravelMessenger/blob/master/src/Contracts/Participation.php) #### Messages -```php - - * - * @property int id - * @property int discussion_id - * @property \Arcanedev\LaravelMessenger\Models\Discussion discussion - * @property int user_id - * @property \Illuminate\Database\Eloquent\Model user - * @property \Illuminate\Database\Eloquent\Model author - * @property int body - * @property \Carbon\Carbon created_at - * @property \Carbon\Carbon updated_at - * @property \Illuminate\Database\Eloquent\Collection participants - * @property \Illuminate\Database\Eloquent\Collection recipients - */ -interface Message -{ - /* ------------------------------------------------------------------------------------------------ - | Relationships - | ------------------------------------------------------------------------------------------------ - */ - /** - * Discussion relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function discussion(); - - /** - * User/Author relationship (alias). - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function author(); - - /** - * User/Author relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function user(); - - /** - * Participants relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function participants(); - - /* ------------------------------------------------------------------------------------------------ - | Getters & Setters - | ------------------------------------------------------------------------------------------------ - */ - /** - * Recipients of this message. - * - * @return \Illuminate\Database\Eloquent\Collection - */ - public function getRecipientsAttribute(); -} -``` +Contract/Interface: [Link](https://github.com/ARCANEDEV/LaravelMessenger/blob/master/src/Contracts/Message.php)