1
votes

I use PhpStorm 2018.1.4. I installed the package laravel-ide-helper. This allows PhpStorm to see model methods, but it doesn't see any chaining methods from Laravel helpers. For example, I have the following code in the controller:

return response()->file($path,['content-type' => 'application/pdf']); 

PhpStorm says to me:

Method 'file' not found in \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response.

How to fix it?

UPD: Of course, after install the package, I ran thees artisan commands:

php artisan ide-helper:generate
php artisan ide-helper:meta
1
Side note: Technically IDE is able to "find Laravel helpers" (response() function is a helper). But it has some issues (because of PHPDoc that Laravel uses and overall "how to document it properly") with locating some methods when chaining. Darryl E. Clarke described it very well. - LazyOne

1 Answers

3
votes

Installing the laravel-ide-helper alone doesn't do anything. You need to run the artisan commands to generate the files that phpstorm will use.

php artisan ide-helper:generate

and

php artisan ide-helper:meta

Will help phpStorm's auto-completion.

Update: Since these are executed, the actual problem is a laravel structure issue:

The helper file() doesn't actually exist in the ResponseFactory (response() returns result of ResponseFactory) so IDE helper can't map to it.

file() does however exist in the Facade so if you were to do:

\Response::file($path,['content-type' => 'application/pdf']) it will auto complete.

It's a work around, but unless file() gets added to the response factory at laravel's level, there's not much ide helper or phpstorm can do.