New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

titasgailius/larastan-extended

An opinionated Larastan extension. Automatically parse model's casts() method.
9,091
Install
composer require titasgailius/larastan-extended
Latest Version:0.0.2
License:MIT
Last Updated:Jun 9, 2025
Links: GitHub  ·  Packagist
Maintainer: TitasGailius

Larastan Extended Demo

Larastan Extended

Larastan Extended is an opinionated Larastan extension that inspects your Laravel application to make static analysis less verbose.

Features

Automatically infer the return type of the casts method.

/**
 * Get the attributes that should be cast.
- *
- * @return array{
- *     user_id: 'integer',
- *     published_at: 'datetime',
- * }
 */
public function casts(): array
{
    return [
        'user_id' => 'integer',
        'published_at' => 'datetime',
    ];
}

Detect non-nullable $request->user() calls in authenticated routes.

Route::get('posts', function (Request $request) {
-    /** @var \App\Models\User */
-    $user = $request->user();
-
-    return $user->posts;
+    return $request->user()->posts;
})->middleware('auth');

Detect non-nullable relationships.

Route::get('teams/{team}/owner', function (Team $team) {
-  /** @var \App\Models\User */
-  $owner = $team->owner;
-
-  return $owner;
+  return $team->owner;
});

Installation

You can install the package via Composer:

composer require --dev titasgailius/larastan-extended

Usage

Include the extension before the Larastan extension.

includes:
+ - vendor/titasgailius/larastan-extended/extension.neon
  - vendor/larastan/larastan/extension.neon

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

655,942,320 9,702
laravel/framework

The Laravel Framework.

617,629,957 34,997
laravel/tinker

Powerful REPL for the Laravel framework.

524,145,802 7,444
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

442,489,569 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

412,228,818 4,664

Version History

Version Released License
0.0.2 MIT
0.0.1 MIT