Releases: overtrue/laravel-follow
Releases · overtrue/laravel-follow
5.2.0
5.1.1
What's Changed
- FIX(README.md): Update sample code by @MartinsOnuoha in #191
- Specified the vendor:publish --class in README.md by @titonova in #195
New Contributors
- @MartinsOnuoha made their first contribution in #191
- @titonova made their first contribution in #195
Full Changelog: 5.1.0...5.1.1
5.1.0
What's Changed
- Added Laravel 10 support.
- Update composer.json by @ams-ryanolson in #184
- Update composer.json by @ams-ryanolson in #185
New Contributors
- @ams-ryanolson made their first contribution in #184
Full Changelog: 5.0.1...5.1.0
5.0.1
5.0.0
Now you can follow any models. #170
What’s Changed
- Default table name
user_followers
changed tofollowables
. - Renamed
followers.follower_id
touser_id
(you can change it in the config fileapp/follow.php
). - Renamed trait
Overtrue\LaravelFollow\Followable
touse Overtrue\LaravelFollow\Traits\Followable
. follow()
,unfollow()
andtoggleFollow()
only accept model usedOvertrue\LaravelFollow\Traits\Followable
trait now.- Removed
Followable::areFollowingEachOther
method. rejectFollowRequestFrom()
,acceptFollowRequestFrow()
,hasRequestedToFollow()
andisFollowedBy
only accept model usedOvertrue\LaravelFollow\Traits\Follower
triat now.- Rename event property
followingId
tofollowable_id
. - Added event property
followable_type
. - Added event property
user_id
. - Added trait
Overtrue\LaravelFollow\Traits\Follower
.
Full change: 59089d5
Migrate from 4.x
-
Update
composer.json
:overtrue/laravel-follow:^5.0
Then run composer update:
composer update
-
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, ];
-
Update the trait
Overtrue\LaravelFollow\Followable
toOvertrue\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; /// <...>
-
Add
doctrine/dbal
package:Before modifying a column, you must install the
doctrine/dbal
package using the Composer package manager.composer require doctrine/dbal
-
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']); }); }
-
Run migrate:
php artisan migrate
-
Done.
4.1.0
4.0.0
Full Changelog: 3.1.1...4.0.0
3.1.1
What's Changed
- Disable un-published migration by @zombozo12 in #169
New Contributors
- @zombozo12 made their first contribution in #169
Full Changelog: 3.1.0...3.1.1
3.1.0
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();