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

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

Frequently asked questions about Larastan
How does Larastan differ from regular PHPStan for Laravel projects?
Larastan is a PHPStan extension specifically designed for Laravel, understanding its magic methods, facades, and service container. Unlike generic PHPStan, it resolves types tied to Laravel’s runtime behavior (e.g., model properties, Blade views, or dependency injection), reducing false positives and catching Laravel-specific bugs early.
Which Laravel versions does Larastan support, and how do I check compatibility?
Larastan 3.x supports Laravel 11.16+ (PHP 8.2+). For older versions (e.g., Laravel 9–11), use Larastan 2.x or 1.x. Check compatibility by comparing your Laravel version with the [supported matrix](https://github.com/larastan/larastan#supported-laravel-versions) in the README. Always align Larastan versions with your Laravel major release.
Can I use Larastan in CI/CD pipelines, and how should I configure it?
Yes, Larastan works seamlessly in CI/CD. Start by adding it as a pre-commit hook or a CI gate (e.g., GitHub Actions). Configure it in your `phpstan.neon` file with a baseline (`--generate-baseline`) for legacy code, then enforce rules incrementally. Cache results to speed up builds, and fail builds on errors to catch issues early.
How do I handle false positives or unsupported Laravel features in Larastan?
False positives can be ignored via `phpstan.neon` or inline comments (`# @phpstan-ignore-line`). For unsupported Laravel features (e.g., custom macros), use `@phpstan-ignore` or extend Larastan’s rules. Document team-specific ignores in a shared config to maintain consistency. Larastan’s Laravel-specific rules already reduce noise compared to generic PHPStan.
Does Larastan work with Laravel packages or only standalone apps?
Larastan works with Laravel packages, but you’ll need to use **orchestra/testbench** to resolve views, models, and dependencies during analysis. Configure Testbench in your package’s `phpstan.neon` to simulate the Laravel environment. This ensures Larastan can validate package-specific logic like custom model properties or Blade templates.
How do I gradually introduce Larastan to a legacy Laravel codebase?
Start by installing Larastan in a non-production branch (`composer require --dev larastan/larastan:^3.0`) and configure `phpstan.neon` with lenient settings (e.g., `level: 5`). Generate a baseline (`phpstan analyse --generate-baseline`) to ignore existing issues, then run manually to document common errors. Incrementally increase the rule level (e.g., 5 → 7 → 9) and enforce in CI/CD.
Will Larastan slow down my development workflow or CI builds?
Larastan runs as a CLI tool outside HTTP requests, so it won’t impact runtime performance. For large codebases, adjust memory limits (`--memory-limit=2G`) or run analysis in parallel. Cache results between runs to speed up CI builds. Start with selective rule enforcement to minimize initial overhead.
Can Larastan validate Blade templates or view strings in Laravel?
Yes, Larastan validates Blade templates and view strings by analyzing their structure and dependencies. It checks for missing views, invalid view paths, and dynamic view names (e.g., `view('user.'.$id)`). This helps catch runtime errors like `View [user.123] not found` before they occur, aligning with Laravel’s view resolution logic.
How do I customize Larastan’s rules for my team or project?
Customize Larastan by extending its `phpstan.neon` configuration or creating project-specific rules. Use `@var` or `@phpstan-type` annotations for custom PHPDoc types (e.g., model properties or view strings). Document team-specific ignores or overrides in a shared config file to ensure consistency across the team. Larastan’s Laravel-specific rules can also be tuned via its [extension API](https://github.com/larastan/larastan#extending-larastan).
Are there alternatives to Larastan for Laravel static analysis?
Alternatives include **Psalm** (with Laravel plugins) or **PHPStan** alone, but neither natively understands Laravel’s magic methods or container. Larastan bridges this gap by booting Laravel’s container during analysis, making it uniquely suited for Laravel projects. For micro-services or non-Laravel PHP, generic tools like PHPStan or Psalm may suffice, but they lack Laravel-specific validation.
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai