PHPackages                             cybex/laravel-reflector - 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. cybex/laravel-reflector

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

cybex/laravel-reflector
=======================

Provides structural information about data Models.

v1.1.1(1y ago)0328[1 PRs](https://github.com/cybex-gmbh/laravel-reflector/pulls)MITPHPPHP ^8.0

Since Sep 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/cybex-gmbh/laravel-reflector)[ Packagist](https://packagist.org/packages/cybex/laravel-reflector)[ Docs](https://github.com/cybex-gmbh/laravel-reflector)[ RSS](/packages/cybex-laravel-reflector/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (11)Used By (0)

Laravel Reflector
=================

[](#laravel-reflector)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e352f74f4207a710aa8b45ffdabc58974e29c9b624891af7713b702b2294f28d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63796265782f6c61726176656c2d7265666c6563746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cybex/laravel-reflector)

This package allows you to get structural information for data models.

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

[](#requirements)

- Illuminate/support: ^8.0
- PHP: ^8.0

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

[](#installation)

You can install the package via composer:

```
composer require cybex/laravel-reflector

```

Usage
-----

[](#usage)

### getModelRelations()

[](#getmodelrelations)

The `getModelRelations()` method returns a Collection of all relations of a Model, with additional information like the name of the relation, relation type, related class and an empty base instance of the given Model from Eloquent.

```
ModelReflector::getModelRelations(User::class);

// Returns

Illuminate\Support\Collection {#5236
    all: [
        "Images" => [
             "relation" => "Images",
             "returnType" => "Illuminate\Database\Eloquent\Relations\HasMany",
             "relatedClass" => "App\Models\Image",
             "relatedModel" => App\Models\Image {#5237},
             "relatedTable" => "images",
             "foreignKeyName" => "id",
             "qualifiedForeignKeyName" => "images.id",
             "isRelationParent" => false,
         ]
    ]
}

```

### getRelationByTarget()

[](#getrelationbytarget)

The `getRelationByTarget()` method returns the name of a Relation between the Model and the Target.

```
$user = new User;
$image = new Image;

ModelReflector::getRelationByTarget($user, $image);

// Returns

'Images'

```

### hasRelation()

[](#hasrelation)

The `hasRelation()` method returns true if a Model has a specific relation.

```
ModelReflector::hasRelation(User::class, 'Images');

// Returns

true

```

### getMethodReturnType()

[](#getmethodreturntype)

The `getMethodReturnType()` method returns the type of a specific method on a given Object or Model class. It returns false when the Method does not exist. It returns null if no return type is type hinted.

```
$user = new User;

ModelReflector::getMethodReturnType($user, 'Images');

// Returns

'Illuminate\Database\Eloquent\Relations\HasMany'

```

### getModelInstance()

[](#getmodelinstance)

The `getModelInstance()` method checks if the given model is an instance of a Model or the fully qualified class name of a Model, and returns the model or the empty Eloquent base Model of the given class.

```
ModelReflector::getModelInstance('App\Models\User');

// Returns an empty object of the User class

```

### getModelClass()

[](#getmodelclass)

The `getModelClass()` method checks if the given model is an instance of a Model or the fully qualified class name of a Model, and returns the class of the given Model.

```
$user = new User;

ModelReflector::getModelClass($user);

// Returns

'App\Models\User'

```

### resolveModelObject()

[](#resolvemodelobject)

The `resolveModelObject()` method resolves a Model based on a given Model or a Class and the according identifier. If no identifier is given, it returns an empty Builder-Model. If the desired Model can not be found, it will return null.

```
ModelReflector::resolveModelObject(Image::class, 10);

// Returns the Image object with the key 10

```

### resolveRelatedModel()

[](#resolverelatedmodel)

The `resolveRelatedModel()` method resolves a related Model by the source and the given Relation. Currently, we only support HasOne or BelongsTo-Relations, as those only return a single Model or null.

```
ModelReflector::resolveRelatedModel($image, 'User');

// Returns the User object that the Image object belongs to

```

### resolveRelatedModelByTarget()

[](#resolverelatedmodelbytarget)

The `resolveRelatedModelByTarget()` method resolves a related Model by the source and the given TargetModel.

```
ModelReflector::resolveRelatedModelByTarget($image, User::class);

// Returns the User object that the Image object belongs to

```

### getModelShortName()

[](#getmodelshortname)

The `getModelShortName()` method returns the Short-Name of a Model.

```
$image = new Image;

ModelReflector::getModelShortName($image);

// Returns

'Image'

```

### getAllModels()

[](#getallmodels)

The `getAllModels()` method returns a Collection of all available Models via the Filesystem.

```
ModelReflector::getAllModels();

// Returns

Illuminate\Support\Collection {#384
    all: [
    "App\Models\User\Image",
    "App\Models\User",
    ],
}

```

### getAllInstantiatableModels()

[](#getallinstantiatablemodels)

The `getAllInstantiatableModels()` method returns a Collection of all instantiatable Model-Classes, which are not Abstract. It returns the full qualified Class-Name as key with the according Short-Name as value.

```
ModelReflector::getAllInstantiatableModels();

// Returns all kinds of empty objects

Illuminate\Support\Collection {#4929
    all: [
    "App\Models\User\Image" => App\Models\User\Image {#4928},
    "App\Models\User" => App\Models\User {#4921},
    ],
}

```

### getInstantiatableModelStructureInformation()

[](#getinstantiatablemodelstructureinformation)

The `getInstantiatableModelStructureInformation()` method returns a Collection of structure information for all instantiatable Model-Classes, which include the fully qualified name of the parent class and the child classes.

```
ModelReflector::getInstantiatableModelStructureInformation();

// Returns

Illuminate\Support\Collection {#1469
    all: [
        "App\Models\User" => Illuminate\Support\Collection {#1482
            all: [
                "parentClass" => null,
                "childClasses" => [
                 "App\Models\User\Image",
                ],
            ],
        },
        "App\Models\User\Image" => Illuminate\Support\Collection {#1483
            all: [
                "parentClass" => "App\Models\User",
                "childClasses" => [],
            ],
        }
    ],
}

```

### getClassFromMorphMap()

[](#getclassfrommorphmap)

The `getClassFromMorphMap()` method returns the class name from the Morph-Map alias (reverse lookup), the alias or null (if strict is true).

```
ModelReflector::getClassFromMorphMap('user');

// Returns

'App\Models\User'

```

### getMorphAliasForClass()

[](#getmorphaliasforclass)

The `getMorphAliasForClass()` method returns the morph alias for the specified Model.

```
ModelReflector::getMorphAliasForClass('App\Models\User');

// Returns

'user'

```

### modelHasTraits()

[](#modelhastraits)

The `modelHasTraits()` method validates if a Model implements one or more specific Traits.

```
ModelReflector::modelHasTraits(User::class, 'Illuminate\Database\Eloquent\Concerns\HasAttributes');

// Returns

true

```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 78.3% 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

Every ~306 days

Total

4

Last Release

705d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dbe92eddb966abe5a1da7a6dabd542589cf8e4855949202305d78c97a22fbf7d?d=identicon)[cybex](/maintainers/cybex)

---

Top Contributors

[![michael-mueller1](https://avatars.githubusercontent.com/u/69632408?v=4)](https://github.com/michael-mueller1 "michael-mueller1 (18 commits)")[![gael-connan-cybex](https://avatars.githubusercontent.com/u/69622662?v=4)](https://github.com/gael-connan-cybex "gael-connan-cybex (5 commits)")

---

Tags

laravelreflectioncybexReflector

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cybex-laravel-reflector/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[nedwors/navigator

A Laravel package to ease defining navigation menus

433.1k](/packages/nedwors-navigator)[xefi/faker-php-laravel

Faker php integration with laravel

1915.1k](/packages/xefi-faker-php-laravel)[dcblogdev/laravel-junie

Install pre-configured guides for Jetbrains Junie

392.5k](/packages/dcblogdev-laravel-junie)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
