Download the PHP package naviisml/laravel-ownables without Composer
On this page you can find all versions of the php package naviisml/laravel-ownables. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download naviisml/laravel-ownables
More information about naviisml/laravel-ownables
Files in naviisml/laravel-ownables
Package laravel-ownables
Short Description A Laravel package to handle ownership relationships between models
License MIT
Informations about the package laravel-ownables
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
- 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
- PHP ^8.0
- Laravel ^9.0, ^10.0, ^11.0 or ^12.0
Installation
Require the package via Composer:
Publish the migration:
Run the migration:
Usage Examples
1. Setting up models
2. Using the package
Giving Ownership
Checking Ownership
Transferring Ownership
Retrieving Owned Items and Owners
Taking Ownership Away
API Reference
HasOwnables Trait
Methods available on owner models:
possessions()- Relationship to ownership recordsownables()- Relationship to owned itemsowns($ownable)- Check if owns a specific itemgiveOwnershipTo($ownable)- Give ownership of an itemtakeOwnershipFrom($ownable)- Remove ownership of an itemtransferOwnership($ownable, $newOwner)- Transfer ownership to another owner
IsOwnable Trait
Methods available on ownable models:
ownerships()- Relationship to ownership recordsowners()- Relationship to ownerscurrentOwner()- Get the current ownerownedBy($owner)- Set ownership to a specific ownerisOwnedBy($owner)- Check if owned by a specific ownertransferOwnershipTo($newOwner)- Transfer ownership to a new owner
Owner Facade
Static methods available via the Owner facade:
Owner::give($owner, $ownable)- Give ownershipOwner::check($owner, $ownable)- Check ownershipOwner::transfer($fromOwner, $toOwner, $ownable)- Transfer ownership
Configuration
You can publish the configuration file to customize the package behavior:
The configuration allows you to customize:
- Default owner model class
- Default ownable model class
- Database table name
Database Structure
The package creates an ownerships table with the following structure:
id- Primary keyowner_id- ID of the owner modelowner_type- Class name of the owner modelownable_id- ID of the ownable modelownable_type- Class name of the ownable modelis_current- Boolean flag indicating if this is the current ownershipcreated_at- Timestamp when ownership was createdupdated_at- Timestamp when ownership was last updated