MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / eloquentClosure

Method eloquentClosure

examples/laravel/app/Demo.php:133–157  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

131 // ── Eloquent Closure Parameter Inference ────────────────────────────────
132
133 public function eloquentClosure(): void
134 {
135 // Eloquent chunk — $orders inferred as Collection
136 BlogAuthor::where('active', true)->chunk(100, function ($orders) {
137 $count = $orders->count(); // resolves to Eloquent Collection
138 echo $count;
139 });
140
141 // Explicit bare type hint inherits inferred generic args for foreach
142 BlogAuthor::where('active', true)->chunk(100, function (Collection $authors) {
143 foreach ($authors as $author) {
144 $author->posts(); // resolves to BlogAuthor via Collection<int, BlogAuthor>
145 }
146 });
147
148 // Eloquent whereHas — $query inferred as Builder<BlogPost> (the related model)
149 BlogAuthor::whereHas('posts', function ($query) {
150 $query->where('published', true); // resolves to Builder<BlogPost>
151 });
152
153 // Dot-notation relation chain
154 BlogPost::whereHas('author', function ($q) {
155 $q->where('active', true); // resolves to Builder<BlogAuthor>
156 });
157 }
158
159
160 // ── Laravel Config & Env Navigation ─────────────────────────────────────

Callers

nothing calls this directly

Calls 3

whereMethod · 0.80
postsMethod · 0.80
countMethod · 0.45

Tested by

no test coverage detected