laravel-follow

This package helps you to add user based follow system to your model.

MIT License

Downloads
332K
Stars
1.2K
Committers
29

Bot releases are hidden (Show)

laravel-follow - 5.2.0 Latest Release

Published by overtrue 7 months ago

Added Laravel 11 support.

Full Changelog: https://github.com/overtrue/laravel-follow/compare/5.1.1...5.2.0

laravel-follow - 5.1.1

Published by overtrue 9 months ago

What's Changed

New Contributors

Full Changelog: https://github.com/overtrue/laravel-follow/compare/5.1.0...5.1.1

laravel-follow - 5.1.0

Published by overtrue over 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/overtrue/laravel-follow/compare/5.0.1...5.1.0

laravel-follow - 5.0.1

Published by overtrue over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/overtrue/laravel-follow/compare/5.0.0...5.0.1

laravel-follow - 5.0.0

Published by overtrue over 2 years ago

Now you can follow any models. #170

What’s Changed

  • Default table name user_followers changed to followables.
  • Renamed followers.follower_id to user_id(you can change it in the config file app/follow.php).
  • Renamed trait Overtrue\LaravelFollow\Followable to use Overtrue\LaravelFollow\Traits\Followable.
  • follow(), unfollow() and toggleFollow() only accept model used Overtrue\LaravelFollow\Traits\Followable trait now.
  • Removed Followable::areFollowingEachOther method.
  • rejectFollowRequestFrom(), acceptFollowRequestFrow(), hasRequestedToFollow() and isFollowedBy only accept model used Overtrue\LaravelFollow\Traits\Follower triat now.
  • Rename event property followingId to followable_id.
  • Added event property followable_type.
  • Added event property user_id.
  • Added trait Overtrue\LaravelFollow\Traits\Follower.

Full change: https://github.com/overtrue/laravel-follow/commit/59089d5f11a0569f7eecef89bdc96f44fb88cc61

Migrate from 4.x

  1. Update composer.json:

    overtrue/laravel-follow:^5.0
    

    Then run composer update:

    composer update
    
  2. Update config file config/follow.php with the following code:

    <?php
    
    return [
        /**
         * Use uuid as primary key.
         */
        'uuids' => false,
        
        /*
         * User tables foreign key name.
         */
        'user_foreign_key' => 'user_id',
    
        /*
         * Table name for followers table.
         */
        'followables_table' => 'followables',
    
        /**
         * Model class name for followers table.
         */
    
        'followables_model' => \Overtrue\LaravelFollow\Followable::class,
    ];
    
    
  3. Update the trait Overtrue\LaravelFollow\Followable to Overtrue\LaravelFollow\Traits\Follower:

    - use Overtrue\LaravelFollow\Followable;
    +use Overtrue\LaravelFollow\Traits\Followable;
    +use Overtrue\LaravelFollow\Traits\Follower;
    
    class User extends Authenticatable
    {
        use HasApiTokens;
        use HasFactory;
        use Notifiable; 
    +   use Follower; 
        use Followable;
    
    /// <...>
    
  4. Add doctrine/dbal package:

    Before modifying a column, you must install the doctrine/dbal package using the Composer package manager.

    composer require doctrine/dbal
    
  5. Create a migration file:

    php artisan make:migration update_user_follower_to_followables --table=user_follower
    

    With contents:

    public function up()
    {
        Schema::rename('user_follower', 'followables');
    
        Schema::table('followables', function (Blueprint $table) {
            $table->renameColumn('following_id', 'followable_id');
            $table->renameColumn('follower_id', config('follow.user_foreign_key', 'user_id'));
            $table->string("followable_type")->default(addslashes((new User)->getMorphClass()));
            $table->index(config('follow.user_foreign_key', 'user_id'));
            $table->index(['followable_type', 'accepted_at']);
        });
    }
    
  6. Run migrate:

    php artisan migrate
    
  7. Done.

laravel-follow - 4.1.0

Published by overtrue over 2 years ago

  • Fixed the problem of duplicate data insertion #166
  • Added approvedFollowings/notApprovedFollowings/approvedFollowers/notApprovedFollowers relations #167 .

Full Changelog: https://github.com/overtrue/laravel-follow/compare/4.0.0...4.1.0

laravel-follow - 4.0.0

Published by overtrue over 2 years ago

laravel-follow - 3.1.1

Published by overtrue over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/overtrue/laravel-follow/compare/3.1.0...3.1.1

laravel-follow - 3.1.0

Published by overtrue almost 3 years ago

Order by followers count

You can query users order by followers count with following methods:

  • orderByFollowersCountDesc()
  • orderByFollowersCountAsc()
  • orderByFollowersCount(string $direction = 'desc')

example:

$users = User::orderByFollowersCountDesc()->get();
$mostPopularUser = User::orderByFollowersCountDesc()->first();
laravel-follow - 2.4.6

Published by overtrue about 3 years ago

laravel-follow - 2.4.5

Published by overtrue over 3 years ago

laravel-follow - 2.4.4

Published by overtrue over 3 years ago

laravel-follow - 2.4.3

Published by overtrue over 3 years ago

laravel-follow - 2.4.2

Published by overtrue over 3 years ago

laravel-follow - 2.4.1

Published by overtrue over 3 years ago

laravel-follow - 3.0.1

Published by overtrue over 3 years ago

laravel-follow - 3.0.0

Published by overtrue over 3 years ago

  • Added Followable::attachFollowStatus()
  • Laravel 8.0+
  • PHP 7.4+
laravel-follow - 2.4.0

Published by overtrue over 3 years ago

  • Added Followable::attachFollowStatus()
laravel-follow - 2.3.0

Published by overtrue over 3 years ago

laravel-follow - 2.2.1

Published by overtrue almost 4 years ago

Package Rankings
Top 0.97% on Packagist.org
Badges
Extracted from project README
Sponsor me Sponsor me
Related Projects