← BACK
Laravel / Validation

Prefer dispatch(new Job(...)) Over Static Job::dispatch()

Punyapal Shah • • 1 min read
edit this tip →

Use dispatch(new ProcessReport($data)) for superior IDE constructor auto-completion and static analysis type checking.

Static Job::dispatch(...) relies on magical __callStatic methods which can bypass IDE parameter type checking. Instantiating job classes directly via dispatch(new Job(...)) guarantees strict type checking.

use App\Jobs\ProcessReport;

// ❌ Static magic method: weak IDE constructor type completion
// ProcessReport::dispatch($reportId);

// ✅ Explicit instantiation: full IDE auto-completion & static analysis
dispatch(new ProcessReport($reportId));
  • Provides full static analysis parameter validation in PHPStan and Psalm
  • makes sure IDE auto-completes constructor parameters accurately
  • Avoids relying on magic __callStatic methods

Related Tips

View all tips →
Laravel Validation

Optimize Large Wildcard Array Validation in Laravel 13.24

Laravel 13.24 introduces dramatic performance optimizations for validating large nested arrays with wildcard rules, reducing validation execution time from 85 seconds to under 1 second.

READ >

// Got a tip in mind? Contributions are always welcome