overtrue/laravel-follow là dự án Backend trên GitHub, viết chủ yếu bằng PHP, với 1.2k sao. :heart: This package helps you to add user based follow system to your model.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
foreach($user->followings()->with('followable')->get() as $following)
{
$following->created_at; // followed at
$following->followable->nickname; // the user attributes
}
foreach($user->followers()->with('followers')->get() as $follower)
{
$follower->created_at; // followed at
$follower->follower->nickname; // the user attributes
}
Follow Requests
If you would like to have some follow requests to need to be accepted by the user being followed, simply override the needsToApproveFollowRequests() method in the model that uses the Followable trait with your custom logic:
public function needsToApproveFollowRequests()
{
// Your custom logic here
return (bool) $this->private;
}
Aggregations
// followings count
$user->followings()->count();
$user->approvedFollowings()->count();
$user->notApprovedFollowings()->count();
// with query where
$user->followings()->where('gender', 'female')->count();
// followers count
$user->followers()->count();
$user->approvedFollowers()->count();
$user->notApprovedFollowers()->count();
List with *_count attribute:
$users = User::withCount(['followings', 'followables'])->get();
// or
$users = User::withCount(['approvedFollowings', 'approvedFollowers'])->get();
foreach($users as $user) {
// $user->followings_count;
// $user->followers_count;
// or
// $user->approved_followings_count;
// $user->approved_followers_count;
}
Attach user follow status to followable collection
You can use Follower::attachFollowStatus(Collection $followables) to attach the user follow status, it will set has_followed attribute to each model of $followables:
To avoid the N+1 issue, you can use eager loading to reduce this operation to just 2 queries. When querying, you may specify which relationships should be eager loaded using the with method:
$users = User::with('followings')->get();
foreach($users as $user) {
$user->isFollowing(2);
}
$users = User::with('followables')->get();
foreach($users as $user) {
$user->isFollowedBy(2);
}
Events
Event
Description
Overtrue\LaravelFollow\Events\Followed
Triggered when the relationship is created.
Overtrue\LaravelFollow\Events\Unfollowed
Triggered when the relationship is deleted.
:heart: Sponsor me
如果你喜欢我的项目并想支持它,点击这里 :heart:
Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
Contributing
You can contribute in one of three ways:
File bug reports using the issue tracker.
Answer questions or fix bugs on the issue tracker.
Contribute new features or update the wiki.
The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/overtrue/laravel-follow là nguồn chính thức.
overtrue/laravel-follow có bao nhiêu sao?
overtrue/laravel-follow có 1.2k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/overtrue/laravel-follow. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
overtrue/laravel-follow có phải mã nguồn mở không?
Có — overtrue/laravel-follow phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/overtrue/laravel-follow.
overtrue/laravel-follow còn đang phát triển không?
Commit gần nhất trên overtrue/laravel-follow là 6 tháng trước (theo timestamp GitHub). Repo có 134 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
overtrue/laravel-follow là gì?
overtrue/laravel-follow (overtrue/laravel-follow) là dự án PHP trên GitHub. Theo mô tả gốc: :heart: This package helps you to add user based follow system to your model.
overtrue/laravel-follow so với các dự án Backend khác thế nào?
overtrue/laravel-follow được TopGit xếp vào nhóm Backend, với 1.2k sao GitHub và viết bằng PHP. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc laravel-follow có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về laravel-follow.