PHPackages                             peltonsolutions/laravel-ownerable - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. peltonsolutions/laravel-ownerable

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

peltonsolutions/laravel-ownerable
=================================

A custom package for Laravel to make it easier to attach and require classes to belong to a tenant.

v1.0.2(1mo ago)0630MITPHPPHP ^8.4

Since May 24Pushed 1mo agoCompare

[ Source](https://github.com/peltonsolutions/laravel-ownerable)[ Packagist](https://packagist.org/packages/peltonsolutions/laravel-ownerable)[ Docs](https://github.com/peltonsolutions/laravel-ownerable)[ RSS](/packages/peltonsolutions-laravel-ownerable/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (3)Dependencies (15)Versions (8)Used By (0)

laravel-ownerable
=================

[](#laravel-ownerable)

A Laravel package by [Pelton Solutions](https://www.nathanpelton.com) that makes it easy to attach models to an owner (tenant) and automatically scope queries to that owner.

A common use case is multi-tenant applications — for example, a `BlogPost` that belongs to an `Account`. The package auto-assigns the owner on creation and filters all queries to the current owner.

Requirements
------------

[](#requirements)

- PHP ^8.4
- Laravel ^11.0

Installation
------------

[](#installation)

Install via Composer:

```
composer require peltonsolutions/laravel-ownerable
```

Publish the config file:

```
php artisan vendor:publish --provider="PeltonSolutions\LaravelOwnerable\LaravelOwnerableServiceProvider"
```

This creates `config/ownerable.php`:

```
return [
    'owner' => env('PELTON_SOLUTIONS_OWNER_CLASS'),
];
```

Set the owner class in your `.env`:

```
PELTON_SOLUTIONS_OWNER_CLASS=App\Models\Account
```

Usage
-----

[](#usage)

### 1. Implement `CanHavePossessions` on the owner model

[](#1-implement-canhavepossessions-on-the-owner-model)

The owner model (e.g. `Account`) must implement the `CanHavePossessions` contract:

```
use PeltonSolutions\LaravelOwnerable\Contracts\CanHavePossessions;

class Account extends Model implements CanHavePossessions
{
    // Return the currently active owner instance (e.g. from session or auth)
    public static function getCurrent(): ?static
    {
        return static::find(session('account_id'));
    }

    // Associate a possessed model with this owner
    public function addPossession(CanBePossessed $possession)
    {
        $possession->ownerable()->associate($this)->save();
    }

    public function getKey()
    {
        return $this->id;
    }
}
```

### 2. Use the `CanBePossessed` trait on owned models

[](#2-use-the-canbepossessed-trait-on-owned-models)

Add the `CanBePossessed` trait (and optionally implement the contract) to any model that should be scoped to an owner. The model must have `ownerable_id` and `ownerable_type` columns (polymorphic morph).

```
use PeltonSolutions\LaravelOwnerable\Contracts\CanBePossessed as CanBePossessedContract;
use PeltonSolutions\LaravelOwnerable\Traits\CanBePossessed;

class BlogPost extends Model implements CanBePossessedContract
{
    use CanBePossessed;
}
```

### What happens automatically

[](#what-happens-automatically)

- **On creation:** If the model has no owner yet and a current owner is available, the owner is automatically associated via `ownerable()->associate($owner)`.
- **On all queries:** A global scope filters results to only records owned by the current owner. If no current owner is found, the query returns no results (`ownerable_id = null`).

### Migration example

[](#migration-example)

```
Schema::create('blog_posts', function (Blueprint $table) {
    $table->id();
    $table->nullableMorphs('ownerable');
    // ... other columns
    $table->timestamps();
});
```

### Bypassing the global scope

[](#bypassing-the-global-scope)

Use `withoutGlobalScope` when you need to query across all owners:

```
BlogPost::withoutGlobalScope('owner')->get();
```

Testing
-------

[](#testing)

```
composer test
```

The test suite uses [Pest](https://pestphp.com/) and covers the `CanBePossessed` trait and observer — including owner resolution, query scoping, and auto-association on creation.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Nathan Pelton](https://www.nathanpelton.com)

License
-------

[](#license)

laravel-ownerable is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance92

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~1 days

Total

3

Last Release

38d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/41953789?v=4)[Pelton Solutions, LLC](/maintainers/peltonsolutions)[@peltonsolutions](https://github.com/peltonsolutions)

---

Top Contributors

[![nathanpelton](https://avatars.githubusercontent.com/u/29257226?v=4)](https://github.com/nathanpelton "nathanpelton (18 commits)")

---

Tags

laravelpeltonsolutions

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/peltonsolutions-laravel-ownerable/health.svg)

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

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[firefly-iii/data-importer

Firefly III Data Import Tool.

8045.8k](/packages/firefly-iii-data-importer)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[ronasit/laravel-helpers

Provided helpers function and some helper class.

2085.6k31](/packages/ronasit-laravel-helpers)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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