定制 user-pixel-error/laravel-friendships 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

user-pixel-error/laravel-friendships

Composer 安装命令:

composer require user-pixel-error/laravel-friendships

包简介

This package gives Eloquent models the ability to manage their friendships.

README 文档

README

This package gives Eloquent models the ability to manage friendships. You can build friend requests, accepted friendships, blocks, and friend groups.

Supported versions

Package version PHP Laravel / Illuminate
<<<<<<< HEAD
Current ^8.2 ^12.0 || ^13.0
=======
Current ^8.2 ^12.0

32f48a81a50a2d5492c417310dbe1a1c9f865d4b

Laravel 12 supports PHP 8.2+, while Laravel 13 requires PHP 8.3+. Composer will automatically resolve compatible versions based on your project.

Models can:

  • Send friend requests
  • Accept friend requests
  • Deny friend requests
  • Block another model
  • Group friends

Installation

Install the package through Composer.

composer require user-pixel-error/laravel-friendships

Laravel will auto-discover the service provider. Publish the config and migrations when you are ready to customize the table names or groups.

php artisan vendor:publish --provider="PixelError\Friendships\FriendshipsServiceProvider" --tag="friendships-config"
php artisan vendor:publish --provider="PixelError\Friendships\FriendshipsServiceProvider" --tag="friendships-migrations"
php artisan migrate

The config file will be published to:

config/friendships.php

Setup a Model

use Illuminate\Foundation\Auth\User as Authenticatable;
use PixelError\Friendships\Traits\Friendable;

class User extends Authenticatable
{
    use Friendable;
    // ...
}

How to use

Check the Test file to see the package in action

Send a Friend Request

$user->befriend($recipient);

Accept a Friend Request

$user->acceptFriendRequest($sender);

Deny a Friend Request

$user->denyFriendRequest($sender);

Remove Friend

$user->unfriend($friend);

Block a Model

$user->blockFriend($friend);

Unblock a Model

$user->unblockFriend($friend);

Check if Model is Friend with another Model

$user->isFriendWith($friend);

Check if Model has a pending friend request from another Model

$user->hasFriendRequestFrom($sender);

Check if Model has already sent a friend request to another Model

$user->hasSentFriendRequestTo($recipient);

Check if Model has blocked another Model

$user->hasBlocked($friend);

Check if Model is blocked by another Model

$user->isBlockedBy($friend);

Get a single friendship

$user->getFriendship($friend);

Get a list of all Friendships

$user->getAllFriendships();

Get a list of pending Friendships

$user->getPendingFriendships();

Get a list of accepted Friendships

$user->getAcceptedFriendships();

Get a list of denied Friendships

$user->getDeniedFriendships();

Get a list of blocked Friendships

$user->getBlockedFriendships();

Get a list of Friend Requests

$user->getFriendRequests();

Get friends collection

$user->getFriends();

Get friends paginator

$user->getFriends($perPage = 20);

Group a friend

$user->groupFriend($friend, 'close_friends');

Remove a friend from a group

$user->ungroupFriend($friend, 'close_friends');

Remove a friend from all groups

$user->ungroupFriend($friend);

Legacy namespace support

Older applications may still use the original package namespace:

use Hootlex\Friendships\Traits\Friendable;
use Hootlex\Friendships\Status;

This package includes Composer-loaded aliases so older imports can continue working while you migrate to the new namespace.

New applications should use:

use PixelError\Friendships\Traits\Friendable;
use PixelError\Friendships\Status;

After installing or updating the package, regenerate Composer autoload files if needed:

composer dump-autoload

Development tools

This package includes Laravel Pint and PHPStan/Larastan for code quality.

composer format       # Format code with Laravel Pint
composer format:test  # Check formatting without modifying files
composer analyse      # Run PHPStan/Larastan
composer test         # Run PHPUnit
composer ci           # Run style check, static analysis, and tests

v1.0.2 maintenance focus

Version v1.0.2 focuses on package stability:

  • Fixed legacy namespace aliases
  • Added Status legacy alias support
  • Added cleaner FriendshipGroup model naming
  • Kept FriendFriendshipGroups for backwards compatibility
  • Added return types to the friendship API
  • Added better tests for aliases, model naming, and return types
  • Added Laravel Pint
  • Added PHPStan/Larastan

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 146
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固