PHPackages                             mateffy/laravel-introspect - 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. mateffy/laravel-introspect

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

mateffy/laravel-introspect
==========================

Analyze Laravel codebases and find structured information about models, routes and other Laravel-specific things.

1.1.2(10mo ago)1698.7k7[3 PRs](https://github.com/Capevace/laravel-introspect/pulls)2MITPHPPHP ^8.2CI passing

Since May 18Pushed 3mo ago3 watchersCompare

[ Source](https://github.com/Capevace/laravel-introspect)[ Packagist](https://packagist.org/packages/mateffy/laravel-introspect)[ Docs](https://github.com/mateffy/laravel-introspect)[ GitHub Sponsors]()[ RSS](/packages/mateffy-laravel-introspect/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (17)Versions (9)Used By (2)

[![](./docs/header@2.webp)](./docs/header@2.webp)

[![Development Tests Status](https://camo.githubusercontent.com/26ea60f4fbf492d6521602b3e2764513070fd500932ecd99bda4e5c73c34971e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f63617065766163652f6c61726176656c2d696e74726f73706563742f72756e2d74657374732e796d6c3f6c6162656c3d6465762532307465737473)](https://camo.githubusercontent.com/26ea60f4fbf492d6521602b3e2764513070fd500932ecd99bda4e5c73c34971e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f63617065766163652f6c61726176656c2d696e74726f73706563742f72756e2d74657374732e796d6c3f6c6162656c3d6465762532307465737473)[![Latest Version](https://camo.githubusercontent.com/842ec4f525a890ce60e57cd222d60a33bf0e9dd3a48405872726ad7513cfff6e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f63617065766163652f6c61726176656c2d696e74726f73706563743f6c6162656c3d6c61746573742b76657273696f6e)](https://camo.githubusercontent.com/842ec4f525a890ce60e57cd222d60a33bf0e9dd3a48405872726ad7513cfff6e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f63617065766163652f6c61726176656c2d696e74726f73706563743f6c6162656c3d6c61746573742b76657273696f6e)

Introspect for Laravel
======================

[](#introspect-for-laravel)

A utility package to analyze Laravel codebases, querying views, models, routes, classes and more directly from your codebase using a type-safe fluent API.

- 🔍 Query views, routes, classes and models with a fluent API
- 🔍 Use wildcards (`*`) to match multiple views, routes, classes and models
- 🪄 Parse properties, relationships + their types and more directly from Eloquent model code
- 🤖 (De-)serialize queries to/from JSON (perfect for LLM tool calling)

QueryAvailable FiltersViewsname, path, used by view, uses view, extendsRoutesname, URI, controller + fn, methods, middlewareClassesname / namespace, extends parent, implements interfaces, uses traits⤷ Models... relationships, properties, casts, fillable, hidden, read/writeable⤷ Commands... signature, description (*coming soon*)> Name and a few other queries even support wildcard queries (e.g. `components.*.paragraph`)

### Who is this for?

[](#who-is-this-for)

Are you working on a complex refactoring job and need to find all the places where a specific view is used? Are you building devtools or other things which need information about the codebase? Do you need structured schema information of your Eloquent data model?

These are all use cases where you need to introspect your codebase and find out where things are used, how they are used and what they are. This package does exactly that.

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

[](#installation)

Install the package via composer:

```
composer require mateffy/laravel-introspect
```

Note

Depending on your use case, it might make sense to install the package as a dev dependency by adding the `--dev` flag to the command.

Usage
-----

[](#usage)

```
use Mateffy\Introspect\Facades\Introspect;

$views = Introspect::views()
    ->whereNameEquals('components.*.button')
    ->whereUsedBy('pages.admin.*')
    ->get();

$routes = Introspect::routes()
    ->whereUsesController(MyController::class)
    ->whereUsesMiddleware('auth')
    ->whereUsesMethod('POST')
    ->get();

$classes = Introspect::classes()
    ->whereImplements(MyInterface::class)
    ->whereUses(MyTrait::class)
    ->get();

$models = Introspect::models()
    ->whereHasProperties(['name', 'email'])
    ->whereHasFillable('password')
    ->get();

// Access Eloquent properties, relationships, casts, etc. directly
$detail = Introspect::model(User::class);

// Model to JSON schema
$schema = $detail->schema();
```

- [Views](#views)
- [Routes](#routes)
- [Classes](#generic-classes)
- [Models](#models)
- [Commands](#commands)
- [Chaining queries with OR and AND](#chaining-orand)

### Views

[](#views)

You can query all of the views you have in your codebase, including those that are provided by other packages and are namespaced with a `prefix::`. View queries return a `Collection` of view names.

> All queries support wildcards, e.g. `components.*.button` or `*.button`

#### Query views by view path

[](#query-views-by-view-path)

```
$views = Introspect::views()
    // Supports wildcards
    ->whereNameEquals('*components.*item')
    ->get();
// -> ['components.item', 'filament::components.dropdown.list.item', ...]

$views = Introspect::views()
    ->whereNameStartsWith('filament::')
    ->get();

$views = Introspect::views()
    ->whereNameEndsWith('button')
    ->get();

$views = Introspect::views()
    ->whereNameContains('button')
    ->get();
```

#### Query all views that are used by specific views

[](#query-all-views-that-are-used-by-specific-views)

```
$routes = Introspect::views()
    ->whereUsedBy('pages.welcome')
    ->get();
// -> ['components.button', 'filament::components.button', ...]

$routes = Introspect::views()
    ->whereUsedBy('pages.*')
    ->get();

$routes = Introspect::views()
    ->whereNotUsedBy('pages.*')
    ->get();
```

#### Query all views that use a specific view

[](#query-all-views-that-use-a-specific-view)

```
$routes = Introspect::views()
    ->whereUses('components.button')
    ->get();

$routes = Introspect::views()
    ->whereUses('*.button')
    ->get();

$routes = Introspect::views()
    ->whereDoesntUse('*.button')
    ->get();
```

#### Query all views that extend a specific view

[](#query-all-views-that-extend-a-specific-view)

```
$routes = Introspect::views()
    ->whereExtends('layouts.app')
    ->get();

$routes = Introspect::views()
    ->whereExtends('layouts.*')
    ->get();

$routes = Introspect::views()
    ->whereDoesntExtend('layouts.*')
    ->get();
```

### Routes

[](#routes)

Query through all the routes registered in your application (think like `artisan route:list` output), including those registered by packages. The routes are returned as a `Collection`.

#### Query all routes that use a controller

[](#query-all-routes-that-use-a-controller)

```
$routes = Introspect::routes()
    ->whereUsesController(MyController::class)
    ->get();
// -> [\Illuminate\Routing\Route, \Illuminate\Routing\Route, ...]

$routes = Introspect::routes()
    ->whereUsesController(MyController::class, 'index')
    ->get();

$routes = Introspect::routes()
    ->whereUsesController(SingleActionController::class, 'index')
    ->get();
```

#### Query all routes that use a specific middleware

[](#query-all-routes-that-use-a-specific-middleware)

```
$routes = Introspect::routes()
    ->whereUsesMiddleware(MyMiddleware::class)
    ->get();

$routes = Introspect::routes()
    ->whereUsesMiddlewares(['tenant', 'auth'])
    ->get();

$routes = Introspect::routes()
    // Match any of the middlewares
    ->whereUsesMiddlewares(['tenant', 'auth'], all: false)
    ->get();

$routes = Introspect::routes()
    ->whereDoesntUseMiddleware('api')
    ->get();
```

#### Query routes by name

[](#query-routes-by-name)

> "Name equals/contains" queries support wildcards, e.g. `api.products.*` or `*.products.*`

```
$routes = Introspect::routes()
    ->whereNameEquals('api.products.*')
    ->get();

$routes = Introspect::routes()
    ->whereNameStartsWith('api.products.')
    ->get();

$routes = Introspect::routes()
    ->whereNameEndsWith('api.products.')
    ->get();

$routes = Introspect::routes()
    ->whereNameDoesntEqual('api.products.*')
    ->get();
```

#### Query routes by path

[](#query-routes-by-path)

> "Path equals/contains" queries support wildcards, e.g. `api/products/*` or `*/products/*`

```
$routes = Introspect::routes()
    ->wherePathStartsWith('api/products')
    ->get();

$routes = Introspect::routes()
    ->wherePathEndsWith('products')
    ->get();

$routes = Introspect::routes()
    ->wherePathContains('products')
    ->get();

$routes = Introspect::routes()
    ->wherePathEquals('api/products*')
    ->get();
```

### Generic Classes

[](#generic-classes)

#### Query by namespace

[](#query-by-namespace)

```
$services = Introspect::classes()
    ->whereName('\App\Services')
    ->get();
```

#### Query by parent

[](#query-by-parent)

```
$blocks = Introspect::classes()
    ->whereExtends(CMS\Block::class)
    ->get();
```

#### Query by interface

[](#query-by-interface)

```
$blocks = Introspect::classes()
    ->whereImplements(CMS\Block::class)
    ->get();
```

#### Query by trait

[](#query-by-trait)

```
$blocks = Introspect::classes()
    ->whereUses(MyTrait::class)
    ->get();
```

### Models

[](#models)

Query Eloquent models based on their properties, attributes (fillable, hidden, appended, readable, writable), and relationship existence. Model queries return a `Collection` of model class strings (e.g., `App\Models\User::class`).

#### Query by Property Existence

[](#query-by-property-existence)

Filter models based on whether they possess specific properties.

```
$models = Introspect::models()
    ->whereHasProperty('created_at')
    ->get();

// Also available: whereDoesntHaveProperty, whereHasProperties, whereDoesntHaveProperties
// Example with multiple properties (any):
$models = Introspect::models()
    ->whereHasProperties(['first_name', 'last_name'], all: false)
    ->get();
```

#### Query by Fillable Properties

[](#query-by-fillable-properties)

Filter models based on their `$fillable` attributes.

```
$models = Introspect::models()
    ->whereHasFillable('title')
    ->get();

// Also available: whereDoesntHaveFillable, whereHasFillableProperties, etc.
$models = Introspect::models()
    ->whereHasFillableProperties(['name', 'description']) // all: true by default
    ->get();
```

#### Query by Hidden Properties

[](#query-by-hidden-properties)

Filter models based on their `$hidden` attributes.

```
$models = Introspect::models()
    ->whereHasHidden('password')
    ->get();

// Also available: whereDoesntHaveHidden, whereHasHiddenProperties, etc.
$models = Introspect::models()
    ->whereDoesntHaveHiddenProperties(['name', 'email'], all: false) // neither name nor email are hidden
    ->get();
```

#### Query by Appended Properties

[](#query-by-appended-properties)

Filter models based on their `$appends` attributes (accessors).

```
$models = Introspect::models()
    ->whereHasAppended('full_name')
    ->get();

// Also available: whereDoesntHaveAppended, whereHasAppendedProperties, etc.
$models = Introspect::models()
    ->whereHasAppendedProperties(['is_active', 'resource_type'])
    ->get();
```

#### Query by Readable Properties

[](#query-by-readable-properties)

Filter models based on "readable" properties (public getters, public properties, or attributes).

```
$models = Introspect::models()
    ->whereHasReadable('name')
    ->get();

// Also available: whereDoesntHaveReadable, whereHasReadableProperties, etc.
$models = Introspect::models()
    ->whereHasReadableProperties(['id', 'email'])
    ->get();
```

#### Query by Writable Properties

[](#query-by-writable-properties)

Filter models based on "writable" properties (public setters or public properties).

```
$models = Introspect::models()
    ->whereHasWritable('status')
    ->get();

// Also available: whereDoesntHaveWritable, whereHasWritableProperties, etc.
$models = Introspect::models()
    ->whereHasWritableProperties(['name', 'settings'])
    ->get();
```

#### Query by Relationship Existence

[](#query-by-relationship-existence)

Filter models based on the existence of specific relationship methods. *Note: This currently checks for method presence, not relationship type or related model details.*

```
$models = Introspect::models()
    ->whereHasRelationship('user')
    ->get();

$models = Introspect::models()
    ->whereDoesntHaveRelationship('logs')
    ->get();
```

### Chaining queries with `OR` and `AND`

[](#chaining-queries-with-or-and-and)

By default, any queries are combined with `AND` logic. However, you can craft more complex queries by chaining together queries with `OR` logic, too. This works for all queries, including models, routes, views and classes.

```
use \Mateffy\Introspect\Query\Contracts\RouteQueryInterface;

$routes = Introspect::routes()
    ->whereNameEquals('api.*')
    ->whereMethod('POST')
    ->or(fn (RouteQueryInterface $query) => $query
        ->whereHasParameter('product') //
        ->whereHasParameter('category')
    )
    ->get();
```

Some methods support multiple parameters, e.g. `whereUsesMiddlewares([...])` or `whereUsesProperties([...])`. These methods have an `all` parameter that defaults to `true`. If set to `false`, the values are checked with `OR` logic too, matching on any of the values.

```
$routes = Introspect::routes()
    ->whereUsesMiddlewares(['tenant', 'auth'], all: false)
    ->get();
```

### Limit the results and paginate just like using Eloquent queries

[](#limit-the-results-and-paginate-just-like-using-eloquent-queries)

*Actual Laravel pagination (`->paginate(...)`) is not yet supported, but you can use `limit` and `offset` to get the results you want.*

```
$models = Introspect::models()
    ->limit(10)
    ->offset(20)
    ->get();
```

DTO Examples
------------

[](#dto-examples)

#### Get all model properties

[](#get-all-model-properties)

```
$model = Introspect::model(User::class);
$properties = $models->properties();
```

#### Get Model as JSON schema

[](#get-model-as-json-schema)

```
$schema = Introspect::model(User::class)->schema();
// -> ['type' => 'object',...]
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance68

Regular maintenance activity

Popularity40

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% 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 ~10 days

Total

5

Last Release

323d ago

### Community

Maintainers

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

---

Top Contributors

[![Capevace](https://avatars.githubusercontent.com/u/10093858?v=4)](https://github.com/Capevace "Capevace (48 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelLukas Mateffylaravel-introspect

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/mateffy-laravel-introspect/health.svg)

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

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[nativephp/mobile

NativePHP for Mobile

82724.0k43](/packages/nativephp-mobile)[nativephp/desktop

NativePHP for Desktop

34020.6k3](/packages/nativephp-desktop)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)

PHPackages © 2026

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