{"id":20244787,"url":"https://github.com/renoki-co/befriended","last_synced_at":"2025-05-15T05:05:09.706Z","repository":{"id":37955806,"uuid":"141194551","full_name":"renoki-co/befriended","owner":"renoki-co","description":"Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.","archived":false,"fork":false,"pushed_at":"2024-07-09T19:48:24.000Z","size":192,"stargazers_count":764,"open_issues_count":4,"forks_count":54,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-14T06:49:49.538Z","etag":null,"topics":["block","blocker","blocking","content-filtering","eloquent","follow","following","laravel","like","liking","media","model","package","php","social","trait","unfollowed-models"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/renoki-co.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"rennokki"}},"created_at":"2018-07-16T21:07:14.000Z","updated_at":"2025-04-02T14:23:47.000Z","dependencies_parsed_at":"2025-03-15T23:30:58.105Z","dependency_job_id":null,"html_url":"https://github.com/renoki-co/befriended","commit_stats":{"total_commits":165,"total_committers":14,"mean_commits":"11.785714285714286","dds":"0.33939393939393936","last_synced_commit":"3b9ea977412c52c4125ad99312526bb8eb2ae8ff"},"previous_names":["rennokki/befriended"],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renoki-co%2Fbefriended","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renoki-co%2Fbefriended/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renoki-co%2Fbefriended/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renoki-co%2Fbefriended/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renoki-co","download_url":"https://codeload.github.com/renoki-co/befriended/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254276446,"owners_count":22043866,"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":["block","blocker","blocking","content-filtering","eloquent","follow","following","laravel","like","liking","media","model","package","php","social","trait","unfollowed-models"],"created_at":"2024-11-14T09:17:23.028Z","updated_at":"2025-05-15T05:05:09.684Z","avatar_url":"https://github.com/renoki-co.png","language":"PHP","funding_links":["https://github.com/sponsors/rennokki"],"categories":[],"sub_categories":[],"readme":"Laravel Befriended\n==================\n\n![CI](https://github.com/renoki-co/befriended/workflows/CI/badge.svg?branch=master)\n[![codecov](https://codecov.io/gh/renoki-co/befriended/branch/master/graph/badge.svg)](https://codecov.io/gh/renoki-co/befriended/branch/master)\n[![StyleCI](https://github.styleci.io/repos/141194551/shield?branch=master)](https://github.styleci.io/repos/141194551)\n[![Latest Stable Version](https://poser.pugx.org/rennokki/befriended/v/stable)](https://packagist.org/packages/rennokki/befriended)\n[![Total Downloads](https://poser.pugx.org/rennokki/befriended/downloads)](https://packagist.org/packages/rennokki/befriended)\n[![Monthly Downloads](https://poser.pugx.org/rennokki/befriended/d/monthly)](https://packagist.org/packages/rennokki/befriended)\n[![License](https://poser.pugx.org/rennokki/befriended/license)](https://packagist.org/packages/rennokki/befriended)\n\nEloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models\n\n## 🤝 Supporting\n\n**If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with [Github Sponsors](https://github.com/sponsors/rennokki). 📦**\n\n[\u003cimg src=\"https://github-content.s3.fr-par.scw.cloud/static/21.jpg\" height=\"210\" width=\"418\" /\u003e](https://github-content.renoki.org/github-repo/21)\n\n## 🚀 Installation\n\nInstall the package:\n\n```bash\n$ composer require rennokki/befriended\n```\n\nPublish the config:\n\n```bash\n$ php artisan vendor:publish --provider=\"Rennokki\\Befriended\\BefriendedServiceProvider\" --tag=\"config\"\n```\n\nPublish the migrations:\n\n```bash\n$ php artisan vendor:publish --provider=\"Rennokki\\Befriended\\BefriendedServiceProvider\" --tag=\"migrations\"\n```\n\n## 🙌 Usage\n\nThe power of example is better here. This package allows you simply to assign followers, blockings or likes without too much effort. What makes the package powerful is that you can filter queries using scopes out-of-the-box.\n\n```php\n$alice = User::where('name', 'Alice')-\u003efirst();\n$bob = User::where('name', 'Bob')-\u003efirst();\n$tim = User::where('name', 'Tim')-\u003efirst();\n\n$alice-\u003efollow($bob);\n\n$alice-\u003efollowing()-\u003ecount(); // 1\n$bob-\u003efollowers()-\u003ecount(); // 1\n\nUser::followedBy($alice)-\u003eget(); // Just Bob shows up\nUser::unfollowedBy($alice)-\u003eget(); // Tim shows up\n```\n\n## Following\n\nTo follow other models, your model should use the `CanFollow` trait and `Follower` contract.\n\n```php\nuse Rennokki\\Befriended\\Traits\\CanFollow;\nuse Rennokki\\Befriended\\Contracts\\Follower;\n\nclass User extends Model implements Follower {\n    use CanFollow;\n    ...\n}\n```\n\nThe other models that can be followed should use `CanBeFollowed` trait and `Followable` contract.\n\n```php\nuse Rennokki\\Befriended\\Traits\\CanBeFollowed;\nuse Rennokki\\Befriended\\Contracts\\Followable;\n\nclass User extends Model implements Followable {\n    use CanBeFollowed;\n    ...\n}\n```\n\nIf your model can both follow \u0026 be followed, you can use `Follow` trait and `Following` contract.\n\n```php\nuse Rennokki\\Befriended\\Traits\\Follow;\nuse Rennokki\\Befriended\\Contracts\\Following;\n\nclass User extends Model implements Following {\n    use Follow;\n    ...\n}\n```\n\nLet's suppose we have an `User` model which can follow and be followed. Within it, we can now check for followers or follow new users:\n\n```php\n$zuck = User::where('name', 'Mark Zuckerberg')-\u003efirst();\n$user-\u003efollow($zuck);\n\n$user-\u003efollowing()-\u003ecount(); // 1\n$zuck-\u003efollowers()-\u003ecount(); // 1\n```\n\nNow, let's suppose we have a `Page` model, than can only be followed:\n\n```php\nuse Rennokki\\Befriended\\Traits\\CanBeFollowed;\nuse Rennokki\\Befriended\\Contracts\\Followable;\n\nclass Page extends Model implements Followable {\n    use CanBeFollowed;\n    ...\n}\n```\n\nBy default, if querying `following()` and `followers()` from the `User` instance, the relationships will return only `User` instances. If you plan to retrieve other instances, such as `Page`, you can pass the model name or model class as an argument to the relationships:\n\n```php\n$zuckPage = Page::where('username', 'zuck')-\u003efirst();\n\n$user-\u003efollow($zuckPage);\n$user-\u003efollowing()-\u003ecount(); // 0, because it doesn't follow any User instance\n$user-\u003efollowing(Page::class)-\u003ecount(); // 1, because it follows only Zuck's page.\n```\n\nOn-demand, you can check if your model follows some other model:\n\n```php\n$user-\u003eisFollowing($friend);\n$user-\u003efollows($friend); // alias\n```\n\nSome users might want to remove followers from their list. The `Followable` trait comes with a `revokeFollower` method:\n\n```php\n$friend-\u003efollow($user);\n\n$user-\u003erevokeFollower($friend);\n```\n\n**Note: Following, unfollowing or checking if following models that do not correctly implement `CanBeFollowed` and `Followable` will always return `false`.**\n\n### Filtering followed/unfollowed models\n\nTo filter followed or unfollowed models (which can be any other model) on query, your model which you will query should use the `Rennokki\\Befriended\\Scopes\\FollowFilterable` trait.\n\nIf your `User` model can only like other `Page` models, your `Page` model should use the trait mentioned.\n\n```php\n$bob = User::where('username', 'john')-\u003efirst();\n$alice = User::where('username', 'alice')-\u003efirst();\n\nUser::followedBy($bob)-\u003eget(); // You will get no results.\nUser::unfollowedBy($bob)-\u003eget(); // You will get Alice.\n\n$bob-\u003efollow($alice);\nUser::followedBy($bob)-\u003eget(); // Only Alice pops up.\n```\n\n## Blocking\n\nMost of the functions are working like the follow feature, but this is helpful when your models would like to block other models.\n\nUse `CanBlock` trait and `Blocker` contract to allow the model to block other models.\n\n```php\nuse Rennokki\\Befriended\\Traits\\CanBlock;\nuse Rennokki\\Befriended\\Contracts\\Blocker;\n\nclass User extends Model implements Blocker {\n    use CanBlock;\n    ...\n}\n```\n\nAdding `CanBeBlocked` trait and `Blockable` contract sets the model able to be blocked.\n\n```php\nuse Rennokki\\Befriended\\Traits\\CanBeBlocked;\nuse Rennokki\\Befriended\\Contracts\\Blockable;\n\nclass User extends Model implements Blockable {\n    use CanBeBlocked;\n    ...\n}\n```\n\nFor both, you should be using `Block` trait \u0026 `Blocking` contract:\n\n```php\nuse Rennokki\\Befriended\\Traits\\Block;\nuse Rennokki\\Befriended\\Contracts\\Blocking;\n\nclass User extends Model implements Blocking {\n    use Block;\n    ...\n}\n```\n\nMost of the methods are the same:\n\n```php\n$user-\u003eblock($user);\n$user-\u003eblock($page);\n$user-\u003eunblock($user);\n\n$user-\u003eblocking(); // Users that this user blocks.\n$user-\u003eblocking(Page::class); // Pages that this user blocks.\n$user-\u003eblockers(); // Users that block this user.\n$user-\u003eblockers(Page::class); // Pages that block this user.\n\n$user-\u003eisBlocking($page);\n$user-\u003eblocks($page); // alias to isBlocking\n```\n\n### Filtering blocked models\n\nBlocking scopes provided takes away from the query the models that are blocked. Useful to stop showing content when your models blocks other models.\n\nMake sure that the model that will be queried uses the  `Rennokki\\Befriended\\Scopes\\BlockFilterable` trait.\n\n```php\n$bob = User::where('username', 'john')-\u003efirst();\n$alice = User::where('username', 'alice')-\u003efirst();\n\nUser::withoutBlockingsOf($bob)-\u003eget(); // You will get Alice and Bob as results.\n\n$bob-\u003eblock($alice);\nUser::withoutBlockingsOf($bob)-\u003eget(); // You will get only Bob as result.\n```\n\n## Liking\n\nApply `CanLike` trait and `Liker` contract for models that can like:\n\n```php\nuse Rennokki\\Befriended\\Traits\\CanLike;\nuse Rennokki\\Befriended\\Contracts\\Liker;\n\nclass User extends Model implements Liker {\n    use CanLike;\n    ...\n}\n```\n\n`CanBeLiked` and `Likeable` trait can be used for models that can be liked:\n\n```php\nuse Rennokki\\Befriended\\Traits\\CanBeLiked;\nuse Rennokki\\Befriended\\Contracts\\Likeable;\n\nclass Page extends Model implements Likeable {\n    use CanBeLiked;\n    ...\n}\n```\n\nPlanning to use both, use the `Like` trait and `Liking` contact:\n\n```php\nuse Rennokki\\Befriended\\Traits\\Like;\nuse Rennokki\\Befriended\\Contracts\\Liking;\n\nclass User extends Model implements Liking {\n    use Like;\n    ...\n}\n```\n\nAs you have already got started with, these are the methods:\n\n```php\n$user-\u003elike($user);\n$user-\u003elike($page);\n$user-\u003eunlike($page);\n\n$user-\u003eliking(); // Users that this user likes.\n$user-\u003eliking(Page::class); // Pages that this user likes.\n$user-\u003elikers(); // Users that like this user.\n$user-\u003elikers(Page::class); // Pages that like this user.\n\n$user-\u003eisLiking($page);\n$user-\u003elikes($page); // alias to isLiking\n```\n\n### Filtering liked content\n\nFiltering liked content can make showing content easier. For example, showing in the news feed posts that weren't liked by an user can be helpful.\n\nThe model you're querying from must use the `Rennokki\\Befriended\\Scopes\\LikeFilterable` trait.\n\nLet's suppose there are 10 pages in the database.\n\n```php\n$bob = User::where('username', 'john')-\u003efirst();\n$page = Page::find(1);\n\nPage::notLikedBy($bob)-\u003eget(); // You will get 10 results.\n\n$bob-\u003elike($page);\nPage::notLikedBy($bob)-\u003eget(); // You will get only 9 results.\nPage::likedBy($bob)-\u003eget(); // You will get one result, the $page\n```\n\n## Follow requests\n\nThis is similar to the way Instagram allows you to request follow of a private profile.\n\nTo follow other models, your model should use the `CanFollow` trait and `Follower` contract.\n\n```php\nuse Rennokki\\Befriended\\Traits\\CanFollow;\nuse Rennokki\\Befriended\\Contracts\\Follower;\n\nclass User extends Model implements Follower {\n    use CanFollow;\n    ...\n}\n```\n\nThe other models that can be followed should use `CanBeFollowed` trait and `Followable` contract.\n\n```php\nuse Rennokki\\Befriended\\Traits\\CanBeFollowed;\nuse Rennokki\\Befriended\\Contracts\\Followable;\n\nclass User extends Model implements Followable {\n    use CanBeFollowed;\n    ...\n}\n```\n\nIf your model can both follow \u0026 be followed, you can use `Follow` trait and `Following` contract.\n\n```php\nuse Rennokki\\Befriended\\Traits\\Follow;\nuse Rennokki\\Befriended\\Contracts\\Following;\n\nclass User extends Model implements Following {\n    use Follow;\n    ...\n}\n```\n\nLet's suppose we have an `User` model which can follow and be followed. Within it, we can now check for follower requests or request to follow a users:\n\n```php\n$zuck = User::where('name', 'Mark Zuckerberg')-\u003efirst();\n$user-\u003efollowRequest($zuck);\n\n$user-\u003efollowRequests()-\u003ecount(); // 1\n$zuck-\u003efollowerRequests()-\u003ecount(); // 1\n$user-\u003efollows($zuck); // false\n$zuck-\u003eacceptFollowRequest($user); // true\n$user-\u003efollows($zuck); // true\n```\n\nNow, let's suppose we have a `Page` model, than can only be followed:\n\n```php\nuse Rennokki\\Befriended\\Traits\\CanBeFollowed;\nuse Rennokki\\Befriended\\Contracts\\Followable;\n\nclass Page extends Model implements Followable {\n    use CanBeFollowed;\n    ...\n}\n```\n\nYou can then request or cancel the follow requests:\n\n```php\n$user-\u003efollowRequest($zuck);\n$user-\u003ecancelFollowRequest($zuck);\n```\n\nThe one being followed can accept or decline the requests:\n\n```php\n$zuck-\u003eacceptFollowRequest($user);\n$zuck-\u003edeclineFollowRequest($user);\n```\n\nBy default, if querying `followRequests()` and `followerRequests()` from the `User` instance, the relationships will return only `User` instances.\n\nIf you plan to retrieve other instances, such as `Page`, you can pass the model name or model class as an argument to the relationships:\n\n```php\n$zuckPage = Page::where('username', 'zuck')-\u003efirst();\n\n$user-\u003efollowRequest($zuckPage);\n$user-\u003efollowRequests()-\u003ecount(); // 0, because it does not have any requests from any User instance\n$user-\u003efollowerRequests(Page::class)-\u003ecount(); // 1, because it has a follow request for Zuck's page.\n```\n\n**Note: Requesting, accepting, declining or checking if following models that do not correctly implement `CanBeFollowed` and `Followable` will always return `false`.**\n\n## 🐛 Testing\n\n``` bash\nvendor/bin/phpunit\n```\n\n## 🤝 Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## 🔒  Security\n\nIf you discover any security related issues, please email alex@renoki.org instead of using the issue tracker.\n\n## 🎉 Credits\n\n- [Alex Renoki](https://github.com/rennokki)\n- [All Contributors](../../contributors)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenoki-co%2Fbefriended","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenoki-co%2Fbefriended","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenoki-co%2Fbefriended/lists"}