oobook / manage-eloquent
Manage the laravel eloquent model relationships, table columns and column types
Requires
- php: >=8.1
Requires (Dev)
- doctrine/dbal: ^3.9
- jeroen-g/laravel-packager: ^2.10
- orchestra/testbench: ^7.0|^8.23.4|^9.0
- phpunit/phpunit: ^9.0|^10.0.7|^11.0
README
This package will help out you to manage the laravel eloquent model relationships, table columns and column types.
Installation
You can install the package via composer:
composer require oobook/manage-eloquent
Usage
You must define return types of relationships in order to use definedRelationships() method, \Illuminate\Database\Eloquent\Relations\BelongsTo i.e. as following.
<?php namespace App\Models; use Oobook\Database\Eloquent\Concerns\ManageEloquent; class Product extends Model { use ManageEloquent; protected $fillable = [ 'name' ]; public function tags(): \Illuminate\Database\Eloquent\Relations\MorphToMany { return $this->morphToMany( Tag::class, 'taggable' ); } public function category(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Category::class); } }
Examples
<?php $product = new Product(); // RELATIONSHIPS // get all defined Relationships $product->definedRelationships(); // ['tags', 'category'] // get relationships by relationship type $product->definedRelations('BelongsTo'), // ['category']; $product->definedRelations(['BelongsTo', 'MorphToMany']), // ['tags', 'category']; // get relation types $product->definedRelationsTypes(), // [ // "category" => "BelongsTo" // "tags" => "MorphToMany" // ] $product->hasRelation('tags') // true; $product->getRelationType('tags') // \Illuminate\Database\Eloquent\Relations\MorphToMany; // COLUMNS $product->hasColumn('name') // true if exists on db table; $product->getColumns() // get the list of columns of the table; // get the list of timestamp columns of the table; $product->getTimestampColumns()
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email oguz.bukcuoglu@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.