calebdw/phpstan-laravel

A PHPStan extension for analysis of Laravel applications and packages.
2,503 30
Install
composer require calebdw/phpstan-laravel
Latest Version:v1.8.0
PHP:^8.3
License:MIT
Last Updated:Sep 10, 2026
Links: GitHub  ·  Packagist
Maintainer: calebdw

Laravel leans on magic: facades, container bindings, dynamic Eloquent properties, method forwarding, macros. A static analyser sees almost none of it on its own, so the parts of your application that carry the most behaviour are the parts it checks least.

This PHPStan extension closes that gap. It boots your application during analysis and combines that with stubs, reflection extensions and schema scanning, so PHPStan can reason about your models, relations, collections, configuration and views.

$user = User::query()->firstOrFail();   // App\User

$user->email;                           // string
$user->emial;                           // Access to an undefined property
$user->accounts;                        // App\AccountCollection<int, App\Account>

User::query()->pluck('name');           // Collection<int, string>
$user->accounts()->pluck('name');       // Collection<int, string>
User::all()->groupBy('email');          // Collection<string, Collection<int, App\User>>

config('auth.defaults.guard');          // string|null
Config::string('auth.defaults.guard');  // string

User::create(['emial' => '...']);       // Property 'emial' does not exist

None of it comes from annotations you write, and it ships rules for the mistakes Laravel will happily let you make at runtime. It works at every PHPStan level, on applications and on packages.

Documentation

To get started, take a look at the official documentation: installation, configuration, every rule, every option and identifier, and the guide for moving over from Larastan.

Contributing

Contributions are welcome: see CONTRIBUTING.md.

Acknowledgments

This package began as a fork of larastan/larastan, created by Can Vural and Nuno Maduro and improved by many contributors over the years. It would not exist without their work.

License

Open-sourced software licensed under the MIT license.

Related Packages

mfn/phpstan-lost-in-translation

Helps find missing translation strings in Laravel applications

5,879 1
prettyyellowdog/lumenstan

Lumenstan - Discover bugs in your code without running it. A phpstan/phpstan wra...

184 0
larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan exte...

71,305,003 6,511