mnurullahsaglam / laravel-owner
This is a simple package to add owner foreign id to models with a trait
1.1
2023-03-20 21:49 UTC
Requires
- php: ^8.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
This package is auto-updated.
Last update: 2024-09-09 11:46:18 UTC
README
This is a simple package to add owner foreign id to models with a trait.
Installation
You can install the package via composer:
composer require mnurullahsaglam/laravel-owner
Usage
- Add
HasOwner
trait to your model.
By default, the owner model is App\Models\User
and the owner key is user_id
. If you want to change these values, you can override them in your model.
use Illuminate\Database\Eloquent\Model; use Mnurullahsaglam\LaravelOwner\HasOwner; use Mnurullahsaglam\LaravelOwner\OwnerSettings; class Post extends Model { use HasOwner; public function getOwnerSettings(): OwnerSettings { return OwnerSettings::create() ->setOwnerModel(App\Models\Owner::class) ->setOwnerKey('owner_id'); } }
You can access the owner model with owner
relationship.
$post = Post::find(1); return $post->owner;
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.