Download the PHP package timgavin/laravel-block without Composer
On this page you can find all versions of the php package timgavin/laravel-block. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download timgavin/laravel-block
More information about timgavin/laravel-block
Files in timgavin/laravel-block
Package laravel-block
Short Description A User can block another User
License MIT
Homepage https://github.com/timgavin/laravel-block
Informations about the package laravel-block
Laravel Block
A simple Laravel package for blocking users.
Requirements
- PHP 8.3 or greater
- Laravel 12 or greater
Installation
Via Composer
Import Laravel Block into your User model and add the trait.
Then run migrations.
Configuration
Publish the config file.
Available options:
Usage
Block a user
Returns true if the user was blocked, false if already blocking.
Unblock a user
Returns true if the user was unblocked, false if not blocking.
Toggle block
Returns true if now blocking, false if unblocked.
Check if a user is blocking another user
Check if a user is blocked by another user
Check if users are mutually blocking each other
Check if there is any block relationship between two users
Get blocking count
Get blockers count
Get the users a user is blocking
Get the users a user is blocking with pagination
Get the users who are blocking a user
Get the users who are blocking a user with pagination
Get the most recent users who are blocking a user
Get an array of IDs of the users a user is blocking
Get an array of IDs of the users who are blocking a user
Get an array of IDs of both blocking and blockers
Get all user IDs involved in any block relationship (single query)
Useful for feed exclusion - returns IDs of users you're blocking AND users blocking you.
Get block status for multiple users in batch
Returns status for multiple users in just 2 queries instead of 2N. Useful for API responses.
Get block status for a single user
Returns bidirectional block status in a single query. Useful for profile pages.
Query Scopes
Exclude blocked users from queries
Excludes users involved in any block relationship with the given user.
Relationships
Access the blocks relationship (users this user is blocking).
Access the blockers relationship (users blocking this user).
Get the block relationship record where this user blocks another.
Get the block relationship record where another user blocks this user.
Get all block relationships between two users.
Caching
Cache the IDs of the users a user is blocking. Default duration is set in config.
Get the cached IDs of the users a user is blocking.
Cache the IDs of the users who are blocking a user.
Get the cached IDs of the users who are blocking a user.
Clear the Blocking cache.
Clear the Blockers cache.
Clear the Blockers cache for another user. Useful after blocking a user to keep their blockers cache in sync.
Clear the Blocking cache for another user.
Note: 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.
Events
Events are dispatched when users block or unblock each other.
Disable events in config.
Query Scopes
Query scopes are available on the Block model.
Upgrading
If upgrading from 1.x, please see the upgrade guide.
Change log
Please see the changelog for more information on what has changed recently.
Testing
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
MIT. Please see the license file for more information.