PHPackages                             jobmetric/laravel-membership - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. jobmetric/laravel-membership

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

jobmetric/laravel-membership
============================

This is a website membership management package for Laravel that you can use in your projects.

1.3.0(10mo ago)61842MITPHPPHP &gt;=8.0.1

Since Jul 24Pushed 10mo ago2 watchersCompare

[ Source](https://github.com/jobmetric/laravel-membership)[ Packagist](https://packagist.org/packages/jobmetric/laravel-membership)[ Docs](https://doc.jobmetric.net/package/laravel-membership)[ RSS](/packages/jobmetric-laravel-membership/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (5)Used By (2)

[![Contributors](https://camo.githubusercontent.com/9d819d38e8469b85e09a25f5da2550eb1132ce3dbd82da01f6f8c0d4702f2f20/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6a6f626d65747269632f6c61726176656c2d6d656d626572736869702e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jobmetric/laravel-membership/graphs/contributors)[![Forks](https://camo.githubusercontent.com/4ab555c73d0dbc45068567e716dcc01203eb1b0cf7ab0f1dcc44d59ba278f13f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6a6f626d65747269632f6c61726176656c2d6d656d626572736869702e7376673f7374796c653d666f722d7468652d6261646765266c6162656c3d466f726b)](https://github.com/jobmetric/laravel-membership/network/members)[![Stargazers](https://camo.githubusercontent.com/df5895e4e42d5fe43fbb45a19743813d40bb5735fd65ee5221651deaf720122e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a6f626d65747269632f6c61726176656c2d6d656d626572736869702e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jobmetric/laravel-membership/stargazers)[![MIT License](https://camo.githubusercontent.com/d468157c3b8f3116d2c606e437e9da7106668ac579c3c9bd3c6b2a175c03e84c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6f626d65747269632f6c61726176656c2d6d656d626572736869702e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jobmetric/laravel-membership/blob/master/LICENCE.md)[![LinkedIn](https://camo.githubusercontent.com/eb590f47a3fca74584d18db8dd3e985ae3d786f50cd41b7530c3af3885da233c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2d4c696e6b6564496e2d626c75652e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d6c696e6b6564696e26636f6c6f72423d353535)](https://linkedin.com/in/majidmohammadian)

Membership for laravel
======================

[](#membership-for-laravel)

This is a website membership management package for Laravel that you can use in your projects.

In this package, you can entrust the members or users of any model or table you have to it and don't worry about anything anymore, this package helps to make user memberships simple and you can entrust any membership to it without worry.

Install via composer
--------------------

[](#install-via-composer)

Run the following command to pull in the latest version:

```
composer require jobmetric/laravel-membership
```

Documentation
-------------

[](#documentation)

To use the services of this package, please follow the instructions below.

In this package, we have two trait classes that must be connected to both sides of the user and member models.

User models can include `user` and `admin` models or anything else that we want to include in the member model.

The member model is a model that wants any user to be a member, such as `post`, `product`, `order`, and anything else.

For example, you need to connect two trait classes to both user and order models.

### User model

[](#user-model)

```
namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use JobMetric\Membership\CanMember;

class User extends Authenticatable
{
    use CanMember;
}
```

### Order model

[](#order-model)

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use JobMetric\Membership\Contracts\MemberContract;
use JobMetric\Membership\HasMember;

class Order extends Model implements MemberContract
{
    use HasMember;

    /**
     * allow the member collection.
     *
     * @return array
     */
    public function allowMemberCollection(): array
    {
        return [
            'owner' => 'single',
            'members' => 'multiple'
        ];
    }
}
```

The allowMemberCollection method must be in the order class, and we define the collections we want to have in the order class.

> The `owner` collection is a `single` collection that has only one member, and the `members` collection is a `multiple` collection that can have multiple members.
>
> The array keys are designed according to the needs of your model fields, and you can use any word, but the value in front of each key must be selected between `single` and `multiple`.
>
> `single`: means that only one member can be in the collection.
>
> `multiple`: means that multiple members can be in the collection.

Now we have connected our two traits to the mentioned models, and now we can use their functions to register and get user membership information in the order model.

`HasMember` trait methods
-------------------------

[](#hasmember-trait-methods)

### `members()`

[](#members)

This method returns the members of the order model.

```
$order = Order::find(1);
$members = $order->members();
```

### `storeMember($person, $collection, $expired_at = null)`

[](#storememberperson-collection-expired_at--null)

This method stores a member in the order model.

> `$person`: The user model that you want to store in the order model.
>
> `$collection`: The collection that you want to store the user in it.
>
> `$expired_at`: The expiration date of the membership. If you do not specify this parameter, the membership will not expire.

```
$order = Order::find(1);
$user = User::find(1);
$order->storeMember($user, 'members');
```

### `forgetMember($person, $collection)`

[](#forgetmemberperson-collection)

This method removes a member from the order model.

> `$person`: The user model that you want to remove from the order model.
>
> `$collection`: The collection that you want to remove the user from it.

```
$order = Order::find(1);
$user = User::find(1);
$order->forgetMember($user, 'members');
```

### `hasMember($person, $collection)`

[](#hasmemberperson-collection)

This method checks if a user is a member of the order model.

> `$person`: The user model that you want to check if it is a member of the order model.
>
> `$collection`: The collection that you want to check if the user is a member of it.

```
$order = Order::find(1);
$user = User::find(1);
$order->hasMember($user, 'members');
```

### `renewMember($person, $collection, $expired_at = null)`

[](#renewmemberperson-collection-expired_at--null)

This method renews the membership of a user in the order model.

> `$person`: The user model that you want to renew the membership in the order model.
>
> `$collection`: The collection that you want to renew the membership in it.
>
> `$expired_at`: The expiration date of the membership. If you do not specify this parameter, the membership will not expire.

```
$order = Order::find(1);
$user = User::find(1);
$order->renewMember($user, 'members');
```

### `updateExpiredAtMember($person, $collection, $expired_at = null)`

[](#updateexpiredatmemberperson-collection-expired_at--null)

This method updates the expiration date of the membership of a user in the order model.

> `$person`: The user model that you want to update the expiration date of the membership in the order model.
>
> `$collection`: The collection that you want to update the expiration date of the membership in it.
>
> `$expired_at`: The expiration date of the membership. If you do not specify this parameter, the membership will not expire.

```
$order = Order::find(1);
$user = User::find(1);
$order->updateExpiredAtMember($user, 'members');
```

### `getPerson($collection = null, $is_expired = false)`

[](#getpersoncollection--null-is_expired--false)

This method returns the user who is a member of the order model.

> `$collection`: The collection that you want to get the user from it. If you do not specify this parameter, the method will return the owner of the order model.
>
> `$is_expired`: If you want to get the expired membership, you can set this parameter to `true`.

```
$order = Order::find(1);
$order->getPerson('members');
```

`CanMember` trait methods
-------------------------

[](#canmember-trait-methods)

### `persons()`

[](#persons)

This method returns the orders that the user is a member of.

```
$user = User::find(1);
$orders = $user->persons();
```

### `storePerson($memberable, $collection, $expired_at = null)`

[](#storepersonmemberable-collection-expired_at--null)

This method stores a user in the order model.

> `$memberable`: The member model that you want to store the user in it.
>
> `$collection`: The collection that you want to store the user in it.
>
> `$expired_at`: The expiration date of the membership. If you do not specify this parameter, the membership will not expire.

```
$user = User::find(1);
$order = Order::find(1);
$user->storePerson($order, 'members');
```

### `forgetPerson($memberable, $collection)`

[](#forgetpersonmemberable-collection)

This method removes a user from the order model.

> `$memberable`: The member model that you want to remove the user from it.
>
> `$collection`: The collection that you want to remove the user from it.

```
$user = User::find(1);
$order = Order::find(1);
$user->forgetPerson($order, 'members');
```

### `hasPerson($memberable, $collection)`

[](#haspersonmemberable-collection)

This method checks if a user is a member of the order model.

> `$memberable`: The member model that you want to check if the user is a member of it.
>
> `$collection`: The collection that you want to check if the user is a member of it.

```
$user = User::find(1);
$order = Order::find(1);
$user->hasPerson($order, 'members');
```

### `renewPerson($memberable, $collection, $expired_at = null)`

[](#renewpersonmemberable-collection-expired_at--null)

This method renews the membership of a user in the order model.

> `$memberable`: The member model that you want to renew the membership in it.
>
> `$collection`: The collection that you want to renew the membership in it.
>
> `$expired_at`: The expiration date of the membership. If you do not specify this parameter, the membership will not expire.

```
$user = User::find(1);
$order = Order::find(1);
$user->renewPerson($order, 'members');
```

### `updateExpiredAtPerson($memberable, $collection, $expired_at = null)`

[](#updateexpiredatpersonmemberable-collection-expired_at--null)

This method updates the expiration date of the membership of a user in the order model.

> `$memberable`: The member model that you want to update the expiration date of the membership in it.
>
> `$collection`: The collection that you want to update the expiration date of the membership in it.
>
> `$expired_at`: The expiration date of the membership. If you do not specify this parameter, the membership will not expire.

```
$user = User::find(1);
$order = Order::find(1);
$user->updateExpiredAtPerson($order, 'members');
```

### `getMember($memberable = null, $collection = null, $is_expired = false)`

[](#getmembermemberable--null-collection--null-is_expired--false)

This method returns the user who is a member of the order model.

> `$memberable`: The member model that you want to get the user from it. If you do not specify this parameter, the method will return the owner of the user model.
>
> `$collection`: The collection that you want to get the user from it. If you do not specify this parameter, the method will return the owner of the user model.
>
> `$is_expired`: If you want to get the expired membership, you can set this parameter to `true`.

```
$user = User::find(1);
$user->getMember('members');
```

Add personable attribute in Resource
------------------------------------

[](#add-personable-attribute-in-resource)

In the member resource, there is a field called `personable` that can display your model, but it must be set as follows.

First, you create a listener for the model you want to display in the member resource.

```
php artisan make:listener AddUserResourceToPersonableResourceListener
```

Then, you add the following code to the listener.

```
use JobMetric\Membership\Events\PersonableResourceEvent;

class AddUserResourceToPersonableResourceListener
{
    public function handle(PersonableResourceEvent $event)
    {
        $personable = $event->personable;

        if (personable instanceof \App\Models\User) {
            $event->resource = new \App\Http\Resources\UserResource($personable);
        }
    }
}
```

Finally, you add the listener to the `EventServiceProvider` class.

```
protected $listen = [
    \JobMetric\Membership\Events\PersonableResourceEvent::class => [
        \App\Listeners\AddUserResourceToPersonableResourceListener::class,
    ],
];
```

The work is done, now when the `MemberResource` is called and if the `UserResource` should be returned, the details of that resource will be displayed in the `personable` attribute.

Add memberable attribute in Resource
------------------------------------

[](#add-memberable-attribute-in-resource)

In the member resource, there is a field called `memberable` that can display your model, but it must be set as follows.

First, you create a listener for the model you want to display in the member resource.

```
php artisan make:listener AddOrderResourceToMemberableResourceListener
```

Then, you add the following code to the listener.

```
use JobMetric\Membership\Events\MemberableResourceEvent;

class AddOrderResourceToMemberableResourceListener
{
    public function handle(MemberableResourceEvent $event)
    {
        $memberable = $event->memberable;

        if ($memberable instanceof \App\Models\User) {
            $event->resource = new \App\Http\Resources\OrderResource($memberable);
        }
    }
}
```

Finally, you add the listener to the `EventServiceProvider` class.

```
protected $listen = [
    \JobMetric\Membership\Events\MemberableResourceEvent::class => [
        \App\Listeners\AddOrderResourceToMemberableResourceListener::class,
    ],
];
```

The work is done, now when the `MemberResource` is called and if the `UserResource` should be returned, the details of that resource will be displayed in the `memberable` attribute.

Events
------

[](#events)

This package contains several events for which you can write a listener as follows

EventDescription`MemberableResourceEvent`This event is called after getting the memberable resource.`PersonableResourceEvent`This event is called after getting the personable resource.`MembershipStoredEvent`This event is called after storing a membership.`MembershipForgetEvent`This event is called after forgetting a membership.`MembershipRenewEvent`This event is called after renewing a membership.`MembershipUpdateExpiredAtEvent`This event is called after updating the expiration date of a membership.`MembershipRemoveExpiredEvent`This event is called after removing the expired memberships.Contributing
------------

[](#contributing)

Thank you for considering contributing to the Laravel Membership! The contribution guide can be found in the [CONTRIBUTING.md](https://github.com/jobmetric/laravel-membership/blob/master/CONTRIBUTING.md).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/jobmetric/laravel-membership/blob/master/LICENCE.md) for more information.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance54

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~116 days

Total

4

Last Release

308d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b00d08bd4b0b765ee2d33719a535e6cb49c04fb945078a0809d5c05e6f16ee96?d=identicon)[majidmohammadian](/maintainers/majidmohammadian)

---

Top Contributors

[![MajidMohammadian](https://avatars.githubusercontent.com/u/2099965?v=4)](https://github.com/MajidMohammadian "MajidMohammadian (54 commits)")[![hassan7303](https://avatars.githubusercontent.com/u/128932029?v=4)](https://github.com/hassan7303 "hassan7303 (1 commits)")

---

Tags

laravellaravel-packagemembermembersmembershippackagelaravelpackagemembersUsersmembershipjobmetricaccountsmembership managementmembership system

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jobmetric-laravel-membership/health.svg)

```
[![Health](https://phpackages.com/badges/jobmetric-laravel-membership/health.svg)](https://phpackages.com/packages/jobmetric-laravel-membership)
```

###  Alternatives

[lab404/laravel-impersonate

Laravel Impersonate is a plugin that allows to you to authenticate as your users.

2.3k16.4M48](/packages/lab404-laravel-impersonate)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
