PHPackages                             naviisml/laravel-ownables - 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. naviisml/laravel-ownables

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

naviisml/laravel-ownables
=========================

A Laravel package to handle ownership relationships between models

1.0.0(5mo ago)057MITPHPPHP ^8.0

Since Jan 21Pushed 5mo agoCompare

[ Source](https://github.com/naviisml/laravel-ownables)[ Packagist](https://packagist.org/packages/naviisml/laravel-ownables)[ RSS](/packages/naviisml-laravel-ownables/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Laravel Ownable Package
=======================

[](#laravel-ownable-package)

A Laravel package to handle ownership relationships between Eloquent models. This package provides a simple and flexible way to manage ownership of any model by any other model in your Laravel application.

Features
--------

[](#features)

- **Flexible Ownership**: Any model can own any other model
- **Ownership Transfer**: Transfer ownership between different owners
- **Ownership History**: Keep track of ownership changes over time
- **Current Owner**: Easily retrieve the current owner of any ownable item
- **Bulk Operations**: Check ownership status and manage multiple ownables
- **Automatic Cleanup**: Automatically clean up ownership records when models are deleted
- **Facade Support**: Use the convenient Owner facade for ownership operations

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

[](#requirements)

- PHP ^8.0
- Laravel ^9.0, ^10.0, ^11.0 or ^12.0

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

[](#installation)

Require the package via Composer:

```
composer require naviisml/ownable
```

Publish the migration:

```
php artisan vendor:publish --provider="Naviisml\Ownable\OwnableServiceProvider" --tag="ownable-migrations"
```

Run the migration:

```
php artisan migrate
```

Usage Examples
--------------

[](#usage-examples)

### 1. Setting up models

[](#1-setting-up-models)

```
use Naviisml\Ownable\Traits\HasOwnables;
use Naviisml\Ownable\Traits\IsOwnable;
use Naviisml\Ownable\Contracts\Ownable as OwnableContract;
use Naviisml\Ownable\Contracts\Owner as OwnerContract;

// Owner model (e.g., User)
class User extends Authenticatable implements OwnerContract
{
    use HasOwnables;
}

// Another Owner model (e.g., Company)
class Company extends Model implements OwnerContract
{
    use HasOwnables;
}

// Ownable model
class Post extends Model implements OwnableContract
{
    use IsOwnable;

    // Optional: restrict which models can own this model
    // If omitted or left empty, any model can be an owner
    protected array $allowedOwners = [
        User::class,
        Company::class,
    ];
}
```

### 2. Using the package

[](#2-using-the-package)

#### Giving Ownership

[](#giving-ownership)

```
$user = User::first();
$post = Post::first();

// Give ownership
$user->giveOwnershipTo($post);
// Or
$post->ownedBy($user);
// Or using facade
Owner::give($user, $post);
```

#### Checking Ownership

[](#checking-ownership)

```
// Check ownership
if ($user->owns($post)) {
    // User owns this post
}
// Or
if ($post->isOwnedBy($user)) {
    // Post is owned by this user
}
// Or using facade
if (Owner::check($user, $post)) {
    // Check ownership using facade
}
```

#### Transferring Ownership

[](#transferring-ownership)

```
// Transfer ownership
$newOwner = User::find(2);
$user->transferOwnership($post, $newOwner);
// Or
$post->transferOwnershipTo($newOwner);
// Or using facade
Owner::transfer($user, $newOwner, $post);
```

#### Retrieving Owned Items and Owners

[](#retrieving-owned-items-and-owners)

```
// Get all owned items
$user->ownables()->get();

// Get current owner of an item
$currentOwner = $post->currentOwner();

// Get all owners (including historical)
$allOwners = $post->owners()->get();

// Get only current owners
$currentOwners = $post->owners()->wherePivot('is_current', true)->get();
```

#### Taking Ownership Away

[](#taking-ownership-away)

```
// Remove ownership
$user->takeOwnershipFrom($post);
```

API Reference
-------------

[](#api-reference)

### HasOwnables Trait

[](#hasownables-trait)

Methods available on owner models:

- `possessions()` - Relationship to ownership records
- `ownables()` - Relationship to owned items
- `owns($ownable)` - Check if owns a specific item
- `giveOwnershipTo($ownable)` - Give ownership of an item
- `takeOwnershipFrom($ownable)` - Remove ownership of an item
- `transferOwnership($ownable, $newOwner)` - Transfer ownership to another owner

### IsOwnable Trait

[](#isownable-trait)

Methods available on ownable models:

- `ownerships()` - Relationship to ownership records
- `owners()` - Relationship to owners
- `currentOwner()` - Get the current owner
- `ownedBy($owner)` - Set ownership to a specific owner
- `isOwnedBy($owner)` - Check if owned by a specific owner
- `transferOwnershipTo($newOwner)` - Transfer ownership to a new owner

### Owner Facade

[](#owner-facade)

Static methods available via the Owner facade:

- `Owner::give($owner, $ownable)` - Give ownership
- `Owner::check($owner, $ownable)` - Check ownership
- `Owner::transfer($fromOwner, $toOwner, $ownable)` - Transfer ownership

Configuration
-------------

[](#configuration)

You can publish the configuration file to customize the package behavior:

```
php artisan vendor:publish --provider="Naviisml\Ownable\OwnableServiceProvider" --tag="ownable-config"
```

The configuration allows you to customize:

- Default owner model class
- Default ownable model class
- Database table name

Database Structure
------------------

[](#database-structure)

The package creates an `ownerships` table with the following structure:

- `id` - Primary key
- `owner_id` - ID of the owner model
- `owner_type` - Class name of the owner model
- `ownable_id` - ID of the ownable model
- `ownable_type` - Class name of the ownable model
- `is_current` - Boolean flag indicating if this is the current ownership
- `created_at` - Timestamp when ownership was created
- `updated_at` - Timestamp when ownership was last updated

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance71

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

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

Unknown

Total

1

Last Release

163d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/43450192?v=4)[Navi](/maintainers/naviisml)[@naviisml](https://github.com/naviisml)

---

Top Contributors

[![naviisml](https://avatars.githubusercontent.com/u/43450192?v=4)](https://github.com/naviisml "naviisml (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/naviisml-laravel-ownables/health.svg)

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

###  Alternatives

[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[crumbls/layup

A visual page builder plugin for Filament 5 — Divi-style grid layouts with extensible widgets.

592.7k2](/packages/crumbls-layup)[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)
