{"id":16666403,"url":"https://github.com/fenos/mex","last_synced_at":"2025-06-25T09:34:15.599Z","repository":{"id":16982868,"uuid":"19745691","full_name":"fenos/Mex","owner":"fenos","description":"Multi participants Chat Api for laravel 4.1","archived":false,"fork":false,"pushed_at":"2014-08-02T19:21:49.000Z","size":306,"stargazers_count":23,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-31T05:23:15.990Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fenos.png","metadata":{"files":{"readme":"README.md","changelog":"Change.log","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-13T15:56:24.000Z","updated_at":"2023-12-22T03:33:24.000Z","dependencies_parsed_at":"2022-08-28T08:51:50.473Z","dependency_job_id":null,"html_url":"https://github.com/fenos/Mex","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/fenos/Mex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fenos%2FMex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fenos%2FMex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fenos%2FMex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fenos%2FMex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fenos","download_url":"https://codeload.github.com/fenos/Mex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fenos%2FMex/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261844860,"owners_count":23218445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T11:10:50.973Z","updated_at":"2025-06-25T09:34:15.537Z","avatar_url":"https://github.com/fenos.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Mex\n==========\n\n### Package out of date Not useful in production ###\n=====\n\n[![Build Status](https://travis-ci.org/fenos/Mex.svg?branch=1.0.0)](https://travis-ci.org/fenos/Mex)\n[![License](https://poser.pugx.org/fenos/mex/license.png)](https://packagist.org/packages/fenos/mex)\n[![Latest Stable Version](https://poser.pugx.org/fenos/mex/v/stable.png)](https://packagist.org/packages/fenos/mex)\n\nHi guys, I want to present Mex, Mex is a simple but powerful API for build a internal multi participants chat system. This API come with a lots features, and the syntax is pretty straightforward, Now you have the tools for build your own multi participants chat with laravel 4. Enjoy it.\n\n* [Installation](#installation)\n* [Documentation](#documentation)\n* [Conversations](#conversations)\n    * [Conversation Exists](#conversation-exists)\n    * [Create Conversations](#create-conversations)\n    * [Archive \u0026 Restore Conversations](#archive--restore-conversations)\n    * [Join \u0026 Leave Conversations](#join--leave-conversations)\n    * [Lists Conversations](#lists-conversations)\n    * [Force remove Conversations](#force-remove-conversations)\n* [Messages](#messages)\n    * [Send Messages](#send-messages)\n    * [Get Messages Conversation](#get-messages-conversation)\n    * [Delete Messages](#delete-messages)\n* [Note](#note)\n* [Credits](#credits)\n\n## Installation ##\n\n### Step 1 ###\n\nAdd it on your composer.json\n\n~~~\n\"fenos/mex\": \"1.0.*\"\n~~~\n\nand run **composer update**\n\n\n### Step 2 ###\n\nAdd the following string to **app/config/app.php**\n\n**Providers array:**\n\n~~~\n'Fenos\\Mex\\MexServiceProvider'\n~~~\n\n**Aliases array:**\n\n~~~\n'Mex'    =\u003e 'Fenos\\Mex\\Facades\\Mex'\n~~~\n\n### Step 3 ###\n\n#### Migration ####\n\nMake sure that your settings on **app/config/database.php** are correct, then make the migration typing:\n\n~~~\nphp artisan migrate --package=\"fenos/mex\"\n~~~\n\n### Step 4 ###\n\n#### Include relations ###\n\nFor include the realtions that mex will need to know you have just to import the Following trait on your model siply like so\n\n~~~\n\n    class User extends Eloquent\n    {\n\n        use \\Fenos\\Mex\\Models\\MexRelations;\n\n    }\n\n~~~\n\nThat's it your have done.\n\n## Documentation ##\n\nAs first approch to Mex you have to know that this package is based on conversations, so before any action, you have to retrive the current conversation\nto work with. Said that we can start.\n\n### Conversations ###\n\nThe code that you will use, in few words, always, for initialize a conversation will be:\n\n~~~\nMex::conversation($conversation_id);\n~~~\n\nAnother useful method is `participants`, with it you can retrive conversations knowing only the participants ID\nBut be aware that when a conversation is started you have to get it having the conversation id. Because if any of the participants\njoin or leave the conversation the conversation will have a different numbers of participants and for retrive it again you\nhave to pass the new participants that was joined or without who leaved the conversation.\n\n~~~\nMex::conversation()-\u003eparticipants(1,2,3,4);\n~~~\n\n#### Conversation Exists ####\n\nIf you wanna check if a conversation exists as said above you can do it in 2 different ways.\n\n**Having the ID of the conversation**\n\n~~~\ntry\n{\n    Mex::conversation($conversation_id)-\u003eexists();\n}\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // do your staff\n}\n~~~\n\n**Having only the participants ID**\n\n~~~\ntry\n{\n    Mex::conversation()-\u003eparticipants(1,2,3,4)-\u003eexists();\n}\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // do your staff\n}\n~~~\n\nOn the `participants()` method you will pass the IDS of the participants \"Users\" (for now). But remember that you can\npass even an **array** of them!\n\n#### Create Conversations ####\n\nFor create conversations is really easy, Let me show the code, it is more easy show it then explain it in this case. Then review it.\n\n~~~\n// this will create a multi conversation between users 1 - 2 and 3\nMex::conversation()-\u003eparticipants(1,2,3)-\u003ecreate(['founder_id' =\u003e 1]);\n\n~~~\n\nSo what's going on here I'm telling to `Mex` that i'm working with a `conversation`, and I know, that I need to create it,\nso I pass the participants that \"will start to chat\", and then I pass the founder id in an array easy hum?.\n\nKeep in mind that the `founder_id` must be specified but you can even omit it on the participants values/array.\n\nAlso **very important** the create method doesn't check if the conversation has been already start between thoose participants, so before create it make sure you check that.\n\n~~~\n\n$participants = [1,2,3];\n$founder = Auth::user()-\u003eid;\ntry\n{\n    Mex::conversation()-\u003eparticipants($participants)-\u003eexists();\n\n    // here means that exists so you can just send a message in the conversation we will see it later\n}\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // conversation not found\n    Mex::conversation()-\u003eparticipants($participants)-\u003ecreate(['founder_id' =\u003e $founder]);\n}\n\n~~~\n\nThat's it!\n\n#### Archive \u0026 Restore Conversations ####\n\n##### Archive #####\n\nArchive conversations doesn't mean delete it, but just store it as archived maybe a old conversation that you don't wanna have as active.\nWith Mex you can do it really easy and quick let me show you.\n\n~~~\ntry\n{\n    Mex::conversation($conversation_id)-\u003efrom($user_id)-\u003earchive(); // that's it, the user 1 has archived the conversation\n}\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // conversation not found\n}\n~~~\n\nSecond approch\n\n~~~\ntry\n{\n    Mex::conversation()-\u003eparticipants(1,2,3)-\u003efrom($user_id)-\u003earchive(); // that's it, the user 1 has archived the conversation\n}\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // conversation not found\n}\n~~~\n\nHow you saw here I used a new method called `from()` this method is really important for determinate who does the action.\nBecause do you know that if the `user with ID 1` archive the conversation that even `User ID 2` is in, **only** `User ID 1` will have it as archived,\nwhile the user 2 still normal. So speicfy always the user with `from()` when you do any action that focus only 1 User.\n\n##### Restore #####\n\nFor restore a conversation and have it again as \"active\" use the method `restore()` instead:\n\n~~~\ntry\n{\n    Mex::conversation($conversation_id)-\u003efrom($user_id)-\u003erestore(); // that's it, the user 1 has restored the conversation\n}\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // conversation not found\n}\n~~~\n\nYou can use even partecipants method here.\n\n#### Lists Conversations ####\n\nDo you need to retrive a nice lists of the conversations that the current user has started or has been invited? Ok well use this one,\nbut keep in mind that the archived conversations will be not showed here.\n\nWhat you aspect from this method? Lists of conversations / informations participants / last message sent\n\n~~~\nMex::conversation()-\u003efrom($user_id)-\u003elists();\n~~~\n\nThis method right now will get all conversations about that user, but if the user has 1000 conversations? Relax you have 3 filters for that\nand i'm sure you know thoose.\n\n~~~\n// limit the result to 10 conversation and order it\nMex::conversation()-\u003efrom($user_id)-\u003elists( array('limit' =\u003e 10,'orderBy' =\u003e 'DESC') );\n\n// paginate it\nMex::conversation()-\u003efrom($user_id)-\u003elists( array(['orderBy' =\u003e 'ASC', 'paginate' =\u003e 10) );\n~~~\n\n**New filter**\n\nif you want exclude the founder informations inside the participants results pass use the filter `founder` with false value like so:\n\n~~~\nMex::conversation()-\u003efrom($user_id)-\u003elists( array(['orderBy' =\u003e 'ASC', 'paginate' =\u003e 10, 'founder' =\u003e false) );\n~~~\n\nIf instead you need to retrive the archived lists of conversations you use this method:\n\n~~~\n// you can have the parameters as above\nMex::conversation()-\u003efrom($user_id)-\u003earchivedLists();\n~~~\n\n#### Join \u0026 Leave Conversations ####\n\nThe user has already a conversation started with others but he want to add someone else. You can give this feature to you chat using the `join()` method\nsee how:\n\n~~~\ntry\n{\n    Mex::conversation($conversation_id)-\u003ejoin(4,5); // user 4 and 5 are joined now in the conversation\n\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // conversation not found\n}\n~~~\n\nInstead if you wanna leave the conversation use `leave()` instead\n\n~~~\ntry\n{\n    Mex::conversation($conversation_id)-\u003eleave(4,5); // user 4 and 5 are leaved now in the conversation\n\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // conversation not found\n}\n~~~\n\n#### Force remove Conversations ####\n\nRemoving the conversations means that, the user will not see the conversation anymore **Only the user that does the action** others participants will still see\nthe conversation. And the conversation can be restored using the `restore` method just in case. Keep also in mind that the user will not leave the conversation if\nhe delete the conversation this is up to you. Let's see how force delete the conversation.\n\n~~~\ntry\n{\n    Mex::conversation($id)-\u003efrom($user_id)-\u003eforceRemove();\n\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // conversation not found\n}\n~~~\n\n## Messages ##\n\nAfter you learned about conversations now is time to focus on the messages (Nothing more hard then conversations).\nSee how it easilly works.\n\n### Send Messages ###\n\nfor send message is really easy let me show the code and then review it.\n\n~~~\ntry\n{\n    Mex::conversation($conversation_id)-\u003emessage('Text of your message')-\u003efrom(1)-\u003esend();\n\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // conversation not found\n}\n~~~\n\nI told you, is almost self explained but I review it. We are getting the conversation and passing the id of it, in this conversation we know that we have to send the message.\nNext, we use `message()` method with inside the text of the message. Next witch user send the message? i specific him with `from()` method. Now Mex know everything\nfor deliver the message on the right place and use `send()`.\n\nNow I want even review Create a conversation and sending the message on the same time! That is the main action that an chat must to have.\n\n~~~\n\ntry\n{\n    // check if the conversation exists\n    $conversation = Mex::conversation()-\u003eparticipants(1,2,3)-\u003eexists();\n\n    // yes exists, the method above give to me the ID of the conversation and i send only the message\n    Mex::conversation($conversation-\u003econversation_id)-\u003emessage('Conversation exists')-\u003efrom(1)-\u003esend();\n}\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // the conversation doesn't exists so I create a new\n    $newConversation = Mex::conversation()-\u003eparticipants(1,2,3)-\u003ecreate(['founder_id'=\u003e 1]);\n\n    // and I send the message to the current conversation\n    $newConversation-\u003emessage('New conversation')-\u003efrom(1)-\u003esend();\n}\n~~~\n\nCool isn't?\n\n### Get Messages Conversation ###\n\nFinally we have almost done, now is time to get the messages of a conversation. Here you have 2 ways to get messages of a conversation.\n\nFirst of all how I mentioned on the documentation the method `from()` is very important for let Mex know wich user want to retreive the messages\nso I'll use the following.\n\n~~~\ntry\n{\n    Mex::conversation($conversation_id)-\u003efrom(1)-\u003eget();\n}\ncatch()\n{\n    // conversation not found\n}\n~~~\n\nUsing `from()` method **no external users can access to conversation if an user ID that not belongs to any of the currents IDS on the conversation**, it will throw\n`ConversationNotFoundException`.\n\nAlso if the user has some massage deleted using `from()` will not show it obviously,they are deleted for this user, but **not for others in the conversation**.\n\nThe second method get the entirely conversation with all deleted messages as well, so is not useful for users but I document it.\n\n~~~\ntry\n{\n    Mex::conversation($conversation_id)-\u003eget();\n}\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // conversation not found\n}\n~~~\n\nIf you want to `limit` or `order` or `paginate` the messages pass the array on the `get()` method\n\n~~~\nMex::conversation($conversation_id)-\u003efrom(1)-\u003eget(['limit' =\u003e 10,'orderBy' =\u003e 'DESC']);\nMex::conversation($conversation_id)-\u003efrom(1)-\u003eget(['orderBy' =\u003e 'DESC','paginate' =\u003e '10']); // paginate as last paramater of the array\n~~~\n\nAlso Important, you can retrive the messages of conversations \"active\" and \"Archived\" but **Not conversation that has been ForceDeleted** it will throw `ConversationNotFoundException`\n\n### Delete Messages ###\n\nThe good feature of deleting messages is that only the user that delete the message will not see it anymore but the others participants still see it.\nLet's see how a user delete a message.\n\n~~~\ntry\n{\n    // this delete the message with id 1 for the user with 1 on the conversation with id 1!! :)\n    Mex::conversation($conversaton_id)-\u003emessage($message_id)-\u003efrom($user_id)-\u003edelete();\n\n    // if you prefer to use from() method after the conversation() method do it is the same\n    Mex::conversation($conversaton_id)-\u003efrom($user_id)-\u003emessage($message_id)-\u003edelete();\n}\ncatch(\\Fenos\\Mex\\Exceptions\\ConversationNotFoundException $e)\n{\n    // conversation not found\n}\n~~~\n\n### Note ###\n\nHow you can see this is the first realease and it seem to promises well. Soon if time permit `Mex` will have new features already designed.\nExample it will come Polymorphic as well, how you can see on the migration files the tables are already setted for it :).\nFor the rest feautures will come out more as surprise. :)\n\nI made it with \u003c3\n\n### Tests ###\n\nFor run the tests make sure to have phpUnit and Mockery installed\n\n### Credits ###\n\n© Copyright Fabrizio Fenoglio\n\nReleased package under MIT Licence.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffenos%2Fmex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffenos%2Fmex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffenos%2Fmex/lists"}