All Projects → overtrue → Laravel Follow

overtrue / Laravel Follow

Licence: mit
❤️ This package helps you to add user based follow system to your model.

Labels

Projects that are alternatives of or similar to Laravel Follow

Laravel Boilerplate
Laravel Boilerplate / Starter Kit with Gentelella Admin Theme
Stars: ✭ 704 (-9.28%)
Mutual labels:  laravel
Laravel View Models
View models in Laravel
Stars: ✭ 722 (-6.96%)
Mutual labels:  laravel
Laravel User Verification
PHP package built for Laravel 5.* to easily handle a user email verification and validate the email
Stars: ✭ 755 (-2.71%)
Mutual labels:  laravel
Chat
A Laravel chat package. You can use this package to create a chat/messaging Laravel application.
Stars: ✭ 710 (-8.51%)
Mutual labels:  laravel
Platform
A modular multilingual CMS built with Laravel 5.
Stars: ✭ 719 (-7.35%)
Mutual labels:  laravel
Laravel Honeypot
Preventing spam submitted through forms
Stars: ✭ 728 (-6.19%)
Mutual labels:  laravel
Rapid.js
An ORM-like Interface and a Router For Your API Requests
Stars: ✭ 700 (-9.79%)
Mutual labels:  laravel
Laravel template with vue
laravel5.5和vue.js结合的前后端分离项目模板,后端使用了laravel的LTS版本(5.5),前端使用了流行的vue-element-template项目。作为程序的起点,可以直接以此为基础来进行业务扩展。模板内容包括基础的用户管理和权限管理、日志管理、集成第三方登录,整合laravel-echo-server 实现了websocket 做到了消息的实时推送,并在此基础上,实现了聊天室和客服功能。权限管理包括后端Token认证和前端vue.js的动态权限,解决了前后端完整分离的情况下,vue.js的认证与权限相关的痛点,已在本人的多个项目中集成使用。
Stars: ✭ 763 (-1.68%)
Mutual labels:  laravel
Tddd
A Laravel Continuous Integration Package
Stars: ✭ 722 (-6.96%)
Mutual labels:  laravel
Sweet Alert
A simple PHP package to show SweetAlerts with the Laravel Framework
Stars: ✭ 753 (-2.96%)
Mutual labels:  laravel
Orm
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
Stars: ✭ 712 (-8.25%)
Mutual labels:  laravel
Laravel
Laravel Model Generator
Stars: ✭ 715 (-7.86%)
Mutual labels:  laravel
Noj
⚡ open-source online judge based on Laravel | 南京邮电大学开源 Online Judge | QQ群:668108264
Stars: ✭ 729 (-6.06%)
Mutual labels:  laravel
Artisan View
👀 Manage your views in Laravel projects through artisan
Stars: ✭ 708 (-8.76%)
Mutual labels:  laravel
Twitter
Twitter API for Laravel 5.5+, 6.x, 7.x & 8.x
Stars: ✭ 755 (-2.71%)
Mutual labels:  laravel
Laravel Searchable
Pragmatically search through models and other sources
Stars: ✭ 701 (-9.66%)
Mutual labels:  laravel
Laravel Caffeine
Keeping Your Laravel Forms Awake.
Stars: ✭ 723 (-6.83%)
Mutual labels:  laravel
Blade Ui Kit
A set of renderless components to utilise in your Laravel Blade views.
Stars: ✭ 763 (-1.68%)
Mutual labels:  laravel
Laravel Ecommerce Example
Code for YouTube series on building a Laravel E-Commerce application.
Stars: ✭ 759 (-2.19%)
Mutual labels:  laravel
Bugsnag Laravel
Bugsnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.
Stars: ✭ 746 (-3.87%)
Mutual labels:  laravel

Laravel Follow

User follow unfollow system for Laravel.

Build Status Latest Stable Version Latest Unstable Version Build Status Scrutinizer Code Quality Code Coverage Total Downloads License

💡 The new version has been split into several packages:

Installing

$ composer require overtrue/laravel-follow -vvv

Migrations

This step is also optional, if you want to custom the pivot table, you can publish the migration files:

$ php artisan vendor:publish --provider="Overtrue\\LaravelFollow\\FollowServiceProvider" --tag=migrations

Usage

Traits

Overtrue\LaravelFollow\Followable

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Overtrue\LaravelFollow\Followable;

class User extends Authenticatable
{
    <...>
    use Followable;
    <...>
}

API

$user1 = User::find(1);
$user2 = User::find(2);

$user1->follow($user2);
$user1->unfollow($user2);
$user1->toggleFollow($user2);
$user1->acceptFollowRequestFrom($user2);
$user1->rejectFollowRequestFrom($user2);

$user1->isFollowing($user2);
$user2->isFollowdBy($user1);
$user2->hasRequestedToFollow($user1);

$user1->areFollowingEachOther($user2);

Get followings:

$user->followings;

Get followers:

$user->followers;

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();

// with query where
$user->followings()->where('gender', 'female')->count();

// followers count
$post->followers()->count();

List with *_count attribute:

$users = User::withCount(['followings', 'followers'])->get();

foreach($users as $user) {
    // $user->followings_count;
    // $user->followers_count;
}

N+1 issue

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('followers')->get();

foreach($users as $user) {
    $user->isFollowedBy(2);
}

Events

Event Description
Overtrue\LaravelFollow\Events\Followd Triggered when the relationship is created.
Overtrue\LaravelFollow\Events\Unfollowd Triggered when the relationship is deleted.

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. 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.

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].