calebdw / phpstan-laravel
A PHPStan extension for analysis of Laravel applications and packages.
Package info
github.com/calebdw/phpstan-laravel
Type:phpstan-extension
pkg:composer/calebdw/phpstan-laravel
Fund package maintenance!
Requires
- php: ^8.3
- illuminate/console: ^12.67.0 || ^13.26.1
- illuminate/container: ^12.67.0 || ^13.26.1
- illuminate/contracts: ^12.67.0 || ^13.26.1
- illuminate/database: ^12.67.0 || ^13.26.1
- illuminate/http: ^12.67.0 || ^13.26.1
- illuminate/pipeline: ^12.67.0 || ^13.26.1
- illuminate/support: ^12.67.0 || ^13.26.1
- phpstan/phpstan: ^2.2.8
Requires (Dev)
- calebdw/pg-schema-parser: ^1.0
- doctrine/coding-standard: ^14.0
- iamcal/sql-parser: ^0.7.0
- laravel/framework: ^12.67.0 || ^13.26.1
- mockery/mockery: ^1.6
- nikic/php-parser: ^5.6
- orchestra/canvas: ^10.0 || ^11
- orchestra/testbench-core: ^10.0 || ^11
- phpmyadmin/sql-parser: ^5.9.0
- phpstan/phpstan-deprecation-rules: ^2.0.1
- phpunit/phpunit: ^12.5.8 || ^13.1.8
Suggests
- calebdw/pg-schema-parser: Required to parse PostgreSQL schema dumps with the `postgres` parser driver (MIT)
- iamcal/sql-parser: Required to parse squashed schema dumps with the `iamcal` parser driver (MIT)
- orchestra/testbench: Using phpstan-laravel for analysing a package needs Testbench
- phpmyadmin/sql-parser: Required to parse squashed schema dumps with the `phpmyadmin` parser driver (GPL-2.0-or-later)
This package is auto-updated.
Last update: 2026-08-26 02:40:08 UTC
README
Teaches PHPStan about Laravel's magic
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.
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.
