Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Larastan Laravel Package

nunomaduro/larastan

Larastan is a PHPStan extension for Laravel that adds strong type inference and “code analysis” by booting the app container. It understands Laravel’s magic, finds bugs early, and improves code quality and developer productivity.

View on GitHub
Deep Wiki
Context7

⚗️ Adds code analysis to Laravel improving developer productivity and code quality.

Frequently asked questions about Larastan
How does Larastan differ from regular PHPStan for Laravel?
Larastan extends PHPStan with Laravel-specific rules, booting your app’s container to resolve dynamic types (e.g., facades, dependency injection) that PHPStan alone can’t detect. It also analyzes Blade templates and migrations for missing translations, undefined variables, and type mismatches.
Which Laravel versions does Larastan support?
Larastan 3.x supports Laravel 11.16+, 2.x covers 9.0–11.16, and 1.x is for Laravel <9.0. Always pin the Larastan version in `composer.json` to avoid compatibility issues with Laravel updates.
Can Larastan analyze Blade templates and migrations?
Yes. Larastan parses Blade files for missing translations, undefined variables, and syntax errors. For migrations, it uses `phpmyadmin/sql-parser` to infer column types, improving type safety in queries. Exclude problematic files temporarily if needed.
How do I install Larastan in a Laravel project?
Run `composer require --dev larastan/larastan` and configure it by extending your `phpstan.neon` with Larastan’s rules. Start with `level: 1` to avoid overwhelming false positives, then incrementally raise the level.
Will Larastan work with Pest or Laravel’s built-in testing?
Larastan integrates with Pest and Testbench but may need adjustments for custom test setups. Focus on analyzing production code first—tests often rely on runtime behavior that static analysis can’t fully resolve.
How can I reduce false positives in Larastan?
Start with `level: 1` and gradually increase. Use `ignoreErrors` in `phpstan.neon` for known issues, and generate a baseline with `phpstan analyse --generate-baseline` for legacy code. Commit baseline files to version control.
Is Larastan suitable for large codebases or CI/CD pipelines?
Yes, but optimize performance by running it in CI/CD (not locally) and using flags like `--memory-limit=1G` or `enableMigrationCache`. Exclude large directories (e.g., `tests/`, `storage/`) in `phpstan.neon` to speed up analysis.
Does Larastan support third-party Laravel packages?
Larastan works with most well-typed packages (e.g., Spatie, Laravel Nova), but poorly documented or legacy packages may produce noise. Test with your package’s version and adjust `phpstan.neon` to ignore package-specific errors if needed.
How do I handle dynamic Laravel features like facades or eval()?
Larastan resolves facades and container bindings dynamically, but heavy use of `eval()`, dynamic class generation, or runtime code manipulation may bypass analysis. Document such cases and suppress errors with `@var` annotations or `ignoreErrors`.
What are the alternatives to Larastan for Laravel static analysis?
Alternatives include PHPStan alone (less Laravel-specific), Psalm (supports Laravel but with different syntax), or Pest’s built-in static analysis (limited). Larastan stands out for its deep Laravel integration, including Blade and migration support.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony