laravel-follows maintained by pharaonic
Description
Polymorphic follows for Laravel Eloquent models, with database-enforced uniqueness and explicit changed-state results.
Author
Last update
2026/11/12 23:45
(dev-develop)
License
Downloads
1
Last update
2026/11/12 23:45
License
Require
- php >=8.3 <8.6
- illuminate/contracts ^13.0
- illuminate/database ^13.0
- illuminate/support ^13.0
Last update
2026/11/12 23:45
License
Require
- php >=8.3 <8.6
- illuminate/contracts ^13.0
- illuminate/database ^13.0
- illuminate/support ^13.0
Last update
2026/11/12 23:45
License
Require
- php >=8.3 <8.6
- illuminate/contracts ^13.0
- illuminate/database ^13.0
- illuminate/support ^13.0
Last update
2026/11/12 23:45
License
Require
- php >=8.2 <8.6
- illuminate/contracts ^12.0
- illuminate/database ^12.0
- illuminate/support ^12.0
Last update
2026/11/12 23:45
License
Require
- php >=8.2 <8.6
- illuminate/contracts ^12.0
- illuminate/database ^12.0
- illuminate/support ^12.0
Last update
2026/11/12 23:45
License
Require
- php >=8.2 <8.5
- illuminate/contracts ^11.0
- illuminate/database ^11.0
- illuminate/support ^11.0
Last update
2026/11/12 23:45
License
Require
- php >=8.2 <8.5
- illuminate/contracts ^11.0
- illuminate/database ^11.0
- illuminate/support ^11.0
Last update
2026/11/12 23:45
License
Require
- php >=8.1 <8.4
- illuminate/contracts ^10.0
- illuminate/database ^10.0
- illuminate/support ^10.0
Last update
2026/11/12 23:45
License
Require
- php >=8.1 <8.4
- illuminate/contracts ^10.0
- illuminate/database ^10.0
- illuminate/support ^10.0
Last update
2026/11/12 23:45
License
Require
- php >=8.0 <8.3
- illuminate/contracts ^9.33
- illuminate/database ^9.33
- illuminate/support ^9.33
Last update
2026/11/12 23:45
License
Require
- php >=8.0 <8.3
- illuminate/contracts ^9.33
- illuminate/database ^9.33
- illuminate/support ^9.33
Last update
2026/11/12 23:45
License
Require
- php >=8.0 <8.2
- illuminate/contracts ^8.75
- illuminate/database ^8.75
- illuminate/support ^8.75
Last update
2026/11/12 23:45
License
Require
- php >=8.0 <8.2
- illuminate/contracts ^8.75
- illuminate/database ^8.75
- illuminate/support ^8.75
Last update
2026/11/12 23:44
License
Require
- php >=8.0 <8.1
- illuminate/contracts ^7.30
- illuminate/database ^7.30
- illuminate/support ^7.30
Last update
2026/11/12 23:44
License
Require
- php >=8.0 <8.1
- illuminate/contracts ^7.30
- illuminate/database ^7.30
- illuminate/support ^7.30
Last update
2026/11/12 23:44
License
Require
- php >=8.0 <8.1
- illuminate/contracts ^6.20
- illuminate/database ^6.20
- illuminate/support ^6.20
Last update
2026/11/12 23:44
License
Require
- php >=8.0 <8.1
- illuminate/contracts ^6.20
- illuminate/database ^6.20
- illuminate/support ^6.20
Last update
2026/11/12 23:29
License
Require
- php >=8.1 <8.4
- illuminate/contracts ^10.0
- illuminate/database ^10.0
- illuminate/support ^10.0
Last update
2026/11/12 23:29
License
Require
- php >=8.2 <8.5
- illuminate/contracts ^11.0
- illuminate/database ^11.0
- illuminate/support ^11.0
Last update
2026/11/12 23:29
License
Require
- php >=8.0 <8.1
- illuminate/contracts ^6.20
- illuminate/database ^6.20
- illuminate/support ^6.20
Last update
2026/11/12 23:29
License
Require
- php >=8.0 <8.1
- illuminate/contracts ^7.30
- illuminate/database ^7.30
- illuminate/support ^7.30
Last update
2026/11/12 23:29
License
Require
- php >=8.0 <8.2
- illuminate/contracts ^8.75
- illuminate/database ^8.75
- illuminate/support ^8.75
Last update
2026/11/12 23:29
License
Require
- php >=8.0 <8.3
- illuminate/contracts ^9.33
- illuminate/database ^9.33
- illuminate/support ^9.33
Last update
2026/11/12 21:33
License
Require
- php >=8.1 <8.4
- illuminate/contracts ^10.0
- illuminate/database ^10.0
- illuminate/support ^10.0
Last update
2026/11/12 21:33
License
Require
- php >=8.2 <8.5
- illuminate/contracts ^11.0
- illuminate/database ^11.0
- illuminate/support ^11.0
Last update
2026/11/12 21:33
License
Require
- php >=8.2 <8.6
- illuminate/contracts ^12.0
- illuminate/database ^12.0
- illuminate/support ^12.0
Last update
2026/11/12 21:33
License
Require
- php >=8.3 <8.6
- illuminate/contracts ^13.0
- illuminate/database ^13.0
- illuminate/support ^13.0
Last update
2026/11/12 21:33
License
Require
- php >=8.0 <8.1
- illuminate/contracts ^6.20
- illuminate/database ^6.20
- illuminate/support ^6.20
Last update
2026/11/12 21:33
License
Require
- php >=8.0 <8.1
- illuminate/contracts ^7.30
- illuminate/database ^7.30
- illuminate/support ^7.30
Last update
2026/11/12 21:33
License
Require
- php >=8.0 <8.2
- illuminate/contracts ^8.75
- illuminate/database ^8.75
- illuminate/support ^8.75
Last update
2026/11/12 21:33
License
Require
- php >=8.0 <8.3
- illuminate/contracts ^9.33
- illuminate/database ^9.33
- illuminate/support ^9.33
Last update
2026/11/12 21:33
License
Require
- php >=8.3 <8.6
- illuminate/contracts ^13.0
- illuminate/database ^13.0
- illuminate/support ^13.0
Last update
2026/11/12 21:33
License
Require
- php >=8.0 <8.1
- illuminate/contracts ^6.20
- illuminate/database ^6.20
- illuminate/support ^6.20
Last update
2026/11/12 21:33
License
Require
- php >=8.0 <8.3
- illuminate/contracts ^9.33
- illuminate/database ^9.33
- illuminate/support ^9.33
Last update
2026/11/05 06:50
License
Require
- php >=8.3 <8.6
- illuminate/contracts ^13.0
- illuminate/database ^13.0
- illuminate/support ^13.0
Last update
2026/11/05 06:50
License
Require
- php >=8.2 <8.6
- illuminate/contracts ^12.0
- illuminate/database ^12.0
- illuminate/support ^12.0
Last update
2026/11/05 06:50
License
Require
- php >=8.2 <8.5
- illuminate/contracts ^11.0
- illuminate/database ^11.0
- illuminate/support ^11.0
Last update
2026/11/05 06:50
License
Require
- php >=8.1 <8.4
- illuminate/contracts ^10.0
- illuminate/database ^10.0
- illuminate/support ^10.0
Last update
2026/11/05 06:50
License
Require
- php >=8.0 <8.3
- illuminate/contracts ^9.33
- illuminate/database ^9.33
- illuminate/support ^9.33
Last update
2026/11/05 06:50
License
Require
- php >=8.0 <8.2
- illuminate/contracts ^8.75
- illuminate/database ^8.75
- illuminate/support ^8.75
Last update
2026/11/05 06:50
License
Require
- php >=8.0 <8.1
- illuminate/contracts ^7.30
- illuminate/database ^7.30
- illuminate/support ^7.30
Last update
2026/11/05 06:50
License
Require
- php >=8.0 <8.1
- illuminate/contracts ^6.20
- illuminate/database ^6.20
- illuminate/support ^6.20
Installation
composer require pharaonic/laravel-follows
php artisan migrate
The service provider is registered automatically, and migrate creates the follows table. Publish the migration only to change it (--tag=follows-migrations), and the configuration only to rename the table or turn off cleanup on delete:
php artisan vendor:publish --tag=follows-config
Usage
Add CanFollow to the model that follows (it does not have to be a user) and HasFollowers to the model that is followed. A model can use both.
use Illuminate\Foundation\Auth\User as Authenticatable;
use Pharaonic\Laravel\Follows\Concerns\CanFollow;
class User extends Authenticatable
{
use CanFollow;
}
use Illuminate\Database\Eloquent\Model;
use Pharaonic\Laravel\Follows\Concerns\HasFollowers;
class Post extends Model
{
use HasFollowers;
}
$user->follow($post); // true: this call created the follow
$user->follow($post); // false: it already existed
$user->isFollowing($post); // true
$user->unfollow($post); // true: this call removed it, false when there was none
$user->toggleFollow($post); // the new state: true when followed
$post->followBy($user); // same as $user->follow($post)
$post->unfollowBy($user); // same as $user->unfollow($post)
$post->followedBy($user); // same as $user->isFollowing($post)
Post::withCount('followers')->with('followers.follower')->get();
Post::whereFollowedBy($user)->latest()->paginate();
$user->followings()->with('followable')->latest()->get();
Documentation
Full documentation: Laravel Follows Documentation.
Support & Security
See SUPPORT.md and SECURITY.md. Contributions are welcome; see CONTRIBUTING.md.
License
MIT. See LICENSE.