{"id":46903175,"url":"https://github.com/timgavin/laravel-block","last_synced_at":"2026-03-11T00:33:51.884Z","repository":{"id":61069167,"uuid":"545076824","full_name":"timgavin/laravel-block","owner":"timgavin","description":"A simple Laravel package for blocking users","archived":false,"fork":false,"pushed_at":"2024-04-27T15:35:27.000Z","size":30,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-19T09:10:06.228Z","etag":null,"topics":["block","blocking","laravel","php8"],"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/timgavin.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":"contributing.md","funding":null,"license":"license.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-10-03T18:38:39.000Z","updated_at":"2025-07-28T18:56:54.000Z","dependencies_parsed_at":"2022-10-09T13:11:08.455Z","dependency_job_id":"2782f61e-963b-4d44-81d6-d8c717efa471","html_url":"https://github.com/timgavin/laravel-block","commit_stats":{"total_commits":11,"total_committers":2,"mean_commits":5.5,"dds":0.09090909090909094,"last_synced_commit":"924658ee60f8b001d0f75784b4fc70f1c279c294"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/timgavin/laravel-block","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timgavin%2Flaravel-block","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timgavin%2Flaravel-block/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timgavin%2Flaravel-block/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timgavin%2Flaravel-block/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timgavin","download_url":"https://codeload.github.com/timgavin/laravel-block/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timgavin%2Flaravel-block/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30363990,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T21:41:54.280Z","status":"ssl_error","status_checked_at":"2026-03-10T21:40:59.357Z","response_time":106,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","blocking","laravel","php8"],"created_at":"2026-03-11T00:33:51.121Z","updated_at":"2026-03-11T00:33:51.849Z","avatar_url":"https://github.com/timgavin.png","language":"PHP","readme":"# Laravel Block\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Total Downloads][ico-downloads]][link-downloads]\n[![Tests][ico-tests]][link-tests]\n\nA simple Laravel package for blocking users.\n\n## Requirements\n- PHP 8.3 or greater\n- Laravel 12 or greater\n\n## Installation\n\nVia Composer\n\n``` bash\n$ composer require timgavin/laravel-block\n```\n\nImport Laravel Block into your User model and add the trait.\n\n```php\nnamespace App\\Models;\n\nuse TimGavin\\LaravelBlock\\LaravelBlock;\n\nclass User extends Authenticatable\n{\n    use LaravelBlock;\n}\n```\n\nThen run migrations.\n\n```\nphp artisan migrate\n```\n\n## Configuration\n\nPublish the config file.\n\n```bash\nphp artisan vendor:publish --tag=laravel-block-config\n```\n\nAvailable options:\n\n```php\nreturn [\n    'cache_duration' =\u003e 60 * 60 * 24, // 24 hours in seconds\n    'dispatch_events' =\u003e true,\n    'user_model' =\u003e null, // falls back to auth config\n];\n```\n\n## Usage\n\n### Block a user\n\nReturns `true` if the user was blocked, `false` if already blocking.\n\n```php\nauth()-\u003euser()-\u003eblock($user);\n```\n\n### Unblock a user\n\nReturns `true` if the user was unblocked, `false` if not blocking.\n\n```php\nauth()-\u003euser()-\u003eunblock($user);\n```\n\n### Toggle block\n\nReturns `true` if now blocking, `false` if unblocked.\n\n```php\nauth()-\u003euser()-\u003etoggleBlock($user);\n```\n\n### Check if a user is blocking another user\n\n```php\n@if (auth()-\u003euser()-\u003eisBlocking($user))\n    You are blocking this user.\n@endif\n```\n\n### Check if a user is blocked by another user\n\n```php\n@if (auth()-\u003euser()-\u003eisBlockedBy($user))\n    This user is blocking you.\n@endif\n```\n\n### Check if users are mutually blocking each other\n\n```php\n@if (auth()-\u003euser()-\u003eisMutuallyBlocking($user))\n    You are both blocking each other.\n@endif\n```\n\n### Check if there is any block relationship between two users\n\n```php\n@if (auth()-\u003euser()-\u003ehasAnyBlockWith($user))\n    There is a block relationship.\n@endif\n```\n\n### Get blocking count\n\n```php\nauth()-\u003euser()-\u003egetBlockingCount();\n```\n\n### Get blockers count\n\n```php\nauth()-\u003euser()-\u003egetBlockersCount();\n```\n\n### Get the users a user is blocking\n\n```php\nauth()-\u003euser()-\u003egetBlocking();\n```\n\n### Get the users a user is blocking with pagination\n\n```php\nauth()-\u003euser()-\u003egetBlockingPaginated(15);\n```\n\n### Get the users who are blocking a user\n\n```php\nauth()-\u003euser()-\u003egetBlockers();\n```\n\n### Get the users who are blocking a user with pagination\n\n```php\nauth()-\u003euser()-\u003egetBlockersPaginated(15);\n```\n\n### Get the most recent users who are blocking a user\n\n```php\n// default limit is 5\nauth()-\u003euser()-\u003egetLatestBlockers($limit);\n```\n\n### Get an array of IDs of the users a user is blocking\n\n```php\nauth()-\u003euser()-\u003egetBlockingIds();\n```\n\n### Get an array of IDs of the users who are blocking a user\n\n```php\nauth()-\u003euser()-\u003egetBlockersIds();\n```\n\n### Get an array of IDs of both blocking and blockers\n\n```php\nauth()-\u003euser()-\u003egetBlockingAndBlockersIds();\n```\n\n### Get all user IDs involved in any block relationship (single query)\n\nUseful for feed exclusion - returns IDs of users you're blocking AND users blocking you.\n\n```php\nauth()-\u003euser()-\u003egetAllBlockUserIds();\n```\n\n### Get block status for multiple users in batch\n\nReturns status for multiple users in just 2 queries instead of 2N. Useful for API responses.\n\n```php\n$userIds = $users-\u003epluck('id')-\u003etoArray();\n$statuses = auth()-\u003euser()-\u003egetBlockStatusForUsers($userIds);\n\n// Returns: [userId =\u003e ['is_blocking' =\u003e bool, 'is_blocked_by' =\u003e bool]]\n```\n\n### Get block status for a single user\n\nReturns bidirectional block status in a single query. Useful for profile pages.\n\n```php\n$status = auth()-\u003euser()-\u003egetBlockStatusFor($user);\n\n// Returns: ['is_blocking' =\u003e bool, 'is_blocked_by' =\u003e bool]\n```\n\n## Query Scopes\n\n### Exclude blocked users from queries\n\nExcludes users involved in any block relationship with the given user.\n\n```php\n// Exclude users blocked by or blocking the authenticated user\nUser::query()-\u003eexcludeBlocked()-\u003eget();\n\n// Exclude users blocked by or blocking a specific user\nUser::query()-\u003eexcludeBlocked($user)-\u003eget();\n```\n\n## Relationships\n\nAccess the blocks relationship (users this user is blocking).\n\n```php\n$user-\u003eblocks;\n```\n\nAccess the blockers relationship (users blocking this user).\n\n```php\n$user-\u003eblockers;\n```\n\nGet the block relationship record where this user blocks another.\n\n```php\n$user-\u003egetBlockingRelationship($otherUser);\n```\n\nGet the block relationship record where another user blocks this user.\n\n```php\n$user-\u003egetBlockerRelationship($otherUser);\n```\n\nGet all block relationships between two users.\n\n```php\n$user-\u003egetBlockRelationshipsWith($otherUser);\n```\n\n## Caching\n\nCache the IDs of the users a user is blocking. Default duration is set in config.\n\n```php\nauth()-\u003euser()-\u003ecacheBlocking();\n\n// custom duration in seconds\nauth()-\u003euser()-\u003ecacheBlocking(3600);\n```\n\nGet the cached IDs of the users a user is blocking.\n\n```php\nauth()-\u003euser()-\u003egetBlockingCache();\n```\n\nCache the IDs of the users who are blocking a user.\n\n```php\nauth()-\u003euser()-\u003ecacheBlockers();\n```\n\nGet the cached IDs of the users who are blocking a user.\n\n```php\nauth()-\u003euser()-\u003egetBlockersCache();\n```\n\nClear the Blocking cache.\n\n```php\nauth()-\u003euser()-\u003eclearBlockingCache();\n```\n\nClear the Blockers cache.\n\n```php\nauth()-\u003euser()-\u003eclearBlockersCache();\n```\n\nClear the Blockers cache for another user. Useful after blocking a user to keep their blockers cache in sync.\n\n```php\nauth()-\u003euser()-\u003eclearBlockersCacheFor($user);\n```\n\nClear the Blocking cache for another user.\n\n```php\nauth()-\u003euser()-\u003eclearBlockingCacheFor($user);\n```\n\nNote: The cache is automatically cleared when calling `block()` or `unblock()`. However, only the current user's cache is cleared. Use `clearBlockersCacheFor()` to clear the target user's blockers cache if needed.\n\n## Events\n\nEvents are dispatched when users block or unblock each other.\n\n```php\nuse TimGavin\\LaravelBlock\\Events\\UserBlocked;\nuse TimGavin\\LaravelBlock\\Events\\UserUnblocked;\n\nEvent::listen(UserBlocked::class, function ($event) {\n    // $event-\u003euserId - the user who blocked\n    // $event-\u003eblockedId - the user who was blocked\n});\n\nEvent::listen(UserUnblocked::class, function ($event) {\n    // $event-\u003euserId - the user who unblocked\n    // $event-\u003eunblockedId - the user who was unblocked\n});\n```\n\nDisable events in config.\n\n```php\n'dispatch_events' =\u003e false,\n```\n\n## Query Scopes\n\nQuery scopes are available on the Block model.\n\n```php\nuse TimGavin\\LaravelBlock\\Models\\Block;\n\n// Get blocks where a user is blocking others\nBlock::whereUserBlocks($userId)-\u003eget();\n\n// Get blocks where a user is being blocked\nBlock::whereUserIsBlockedBy($userId)-\u003eget();\n\n// Get all blocks involving a user\nBlock::involvingUser($userId)-\u003eget();\n```\n\n## Upgrading\n\nIf upgrading from 1.x, please see the [upgrade guide](UPGRADE.md).\n\n## Change log\n\nPlease see the [changelog](changelog.md) for more information on what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Security\n\nIf you discover any security related issues, please email tim@timgavin.me instead of using the issue tracker.\n\n## License\n\nMIT. Please see the [license file](license.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/timgavin/laravel-block.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/timgavin/laravel-block.svg?style=flat-square\n[ico-tests]: https://img.shields.io/github/actions/workflow/status/timgavin/laravel-block/tests.yml?branch=master\u0026label=tests\u0026style=flat-square\n\n[link-packagist]: https://packagist.org/packages/timgavin/laravel-block\n[link-downloads]: https://packagist.org/packages/timgavin/laravel-block\n[link-tests]: https://github.com/timgavin/laravel-block/actions/workflows/tests.yml\n[link-author]: https://github.com/timgavin\n[link-contributors]: ../../contributors\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimgavin%2Flaravel-block","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimgavin%2Flaravel-block","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimgavin%2Flaravel-block/lists"}