Download the PHP package ghanem/friendship without Composer

On this page you can find all versions of the php package ghanem/friendship. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package friendship

Laravel Friendship

tests Latest Version on Packagist Total Downloads

A polymorphic friendship system for Laravel: friend requests, accept/deny, blocking, mutual friends, counts, and events. Any Eloquent model can befriend any other model type — not just users.

Requires PHP 8.1+ and Laravel 10, 11, 12, or 13.

Laravel PHP
10 8.1 – 8.4
11 8.2 – 8.4
12 8.2 – 8.4
13 8.3 – 8.4

Laravel 10 and 11 are past Laravel's own security-support window. This package is tested against them on every release — with real tagged framework versions, not branch heads — but the framework itself no longer receives security patches, so Composer flags every published 10.x and 11.x release. Prefer 12 or 13 for new projects.

Installation

The service provider is auto-discovered. Publish and run the migration:

Setup

Add the trait to any model:

Implementing the contract is optional but recommended — it guarantees your model exposes the full API.

Usage

Friend requests

befriend() returns null (no-op) when a pending, accepted, or blocked relationship already exists in either direction.

Blocking

Blocking removes any pending, accepted, or denied row between the pair and remembers who did the blocking. Calling block() again on someone you already blocked is a no-op that keeps the original row.

Blocks are per-direction. A → B and B → A are separate rows and can both exist at once. Being blocked does not let you clear the other party's block: if A blocks B and B then blocks A, B's later unblock($a) removes only B's own block — A's block stays in force, and B still cannot befriend A. Only the blocker can lift their own block.

With a mutual block in place there are two rows for the pair, one per direction. getFriendship() returns the caller's own row ($me->getFriendship($you) returns the row $me sent), so it never tells you who blocked whom — use hasBlocked() / isBlockedBy() for that.

Checks

All checks return bool and are safe to call when no relationship exists.

Lists

List methods return real Collections with sender/recipient eager-loaded — no N+1 queries.

Mutual friends & counts

Events

Every action fires an event carrying the Friendship model ($event->friendship):

Event Fired when
Ghanem\Friendship\Events\FriendRequestSent a request is sent
Ghanem\Friendship\Events\FriendRequestAccepted a request is accepted
Ghanem\Friendship\Events\FriendRequestDenied a request is denied
Ghanem\Friendship\Events\Unfriended an accepted friendship is removed
Ghanem\Friendship\Events\UserBlocked a model is blocked
Ghanem\Friendship\Events\UserUnblocked a model is unblocked

Listen to them like any Laravel event, e.g. to send a notification when a request arrives.

Statuses

Ghanem\Friendship\Status is a backed enum: Pending (0), Accepted (1), Denied (2), Blocked (3). The status attribute on Friendship is cast to it automatically.

Upgrading from 1.x

v2 is a clean break. Database rows are compatible (same table, same status values), but the API changed:

Filament admin panel

friendship-filament on Packagist

ghanem/friendship-filament adds a Filament panel plugin for this package:

It requires Filament 4 or 5, which means Laravel 11.28+ — this core package still supports Laravel 10, the plugin does not.

Limitations

The unique index is directional — A → B and B → A are distinct rows. Two befriend() calls in opposite directions racing at the same instant can therefore both succeed, leaving two pending requests for the same pair; the database cannot reject the second one. Everything else stays consistent (accepting either one makes them friends), but if you expect that kind of concurrency, wrap the call in your own lock keyed on the pair.

Testing

Related packages

Credits

This package began life in 2015 as an MIT-licensed package by DraperStudio / PackageBackup, whose original repository is no longer published. It has been maintained by GAIT ever since, across Laravel 5 through 13. The original copyright notice is retained in LICENSE.

License

MIT. See LICENSE.


All versions of friendship with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ghanem/friendship contains the following files

Loading the files please wait ...