This package will help out you to manage the laravel eloquent model relationships, table columns and column types.
You can install the package via composer:
composer require oobook/manage-eloquentYou 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);
}
}<?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->getTableColumns() // get the list of columns of the table;
// get the list of timestamp columns of the table;
$product->getTimestampColumns() composer testPlease see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email oguz.bukcuoglu@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.