I make right usage of Laravel's facades and PhpStorm gives me warnings, why is that?
And on image I pointed "x" for some...types of data? In functions I use, why do I have these? How to remove them?

- 17,074
- 5
- 83
- 129

- 77
- 2
- 6
-
[This is a feature of phpstorm 2017.1](https://blog.jetbrains.com/phpstorm/2017/03/new-in-phpstorm-2017-1-parameter-hints/). The blog link also has instructions on how to remove it: *"Or you can turn the hints off altogether, by navigating to Editor | General | Appearance and deselecting Show parameter name hints."* – h2ooooooo Jul 26 '17 at 17:39
-
And what about facades warnings? @h2ooooooo – Krystian Polska Jul 26 '17 at 17:50
-
1You're not using facades. You've imported the classes, and on the first, Categories, the IDE is telling you that the get method is not a static method. – Luke Waite Jul 26 '17 at 17:51
-
@LukeWaite Please can you explain me why I am not using facades? All the time I heard that this way is of ;using facades; : – Krystian Polska Jul 26 '17 at 18:14
-
Those are not facades but magic methods of the Model Class, you just want to use `::query()->whereIn` instead of `::whereIn` for the warning to go away – Tofandel Dec 13 '21 at 15:01
1 Answers
Using facades with Laravel
You're not using facades. You've imported the classes, and on the first, Categories, the IDE is telling you that the get method is not a static method.
Just import the facade instead (if it exist).
See the documentation on Facades to learn more on how to use the available facades and how to define your own.
A facade class should look like this:
use Illuminate\Support\Facades\Facade;
class Cache extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'cache';
}
}
Where the 'cache'
string is the name of a service container binding and defined in a service provider, something like this:
use App\Cache\MyCache;
use Illuminate\Support\ServiceProvider;
class CacheServiceProvider extends ServiceProvider
{
/**
* Register bindings in the container.
*
* @return void
*/
public function register()
{
$this->app->singleton('cache', function ($app) {
return new MyCache();
});
}
}
Fixing the warnings with Facades
That being said, I was tired of the warnings and the missing auto-completion and highlighting with facades so I also searched to find a way to fix these.
I came upon laravel-ide-helper which adds Laravel CLI commands that generates php files that only serves to be parsed by your IDE.
Install
Require this package with composer using the following command:
composer require barryvdh/laravel-ide-helper
After updating composer, add the service provider to the providers array in
config/app.php
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class
, To install this package on only development systems, add the--dev
flag to your composer command:composer require --dev barryvdh/laravel-ide-helper
In Laravel, instead of adding the service provider in the
config/app.php
file, you can add the following code to yourapp/Providers/AppServiceProvider.php
file, within theregister()
method:public function register() { if ($this->app->environment() !== 'production') { $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); } // ... }
This will allow your application to load the Laravel IDE Helper on non-production enviroments.
Automatic phpDoc generation for Laravel Facades
You can now re-generate the docs yourself (for future updates)
php artisan ide-helper:generate
Note:
bootstrap/compiled.php
has to be cleared first, so runphp artisan clear-compiled
before generating (andphp artisan optimize
after).You can configure your
composer.json
to do this after each commit:"scripts":{ "post-update-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postUpdate", "php artisan ide-helper:generate", "php artisan ide-helper:meta", "php artisan optimize" ] },
The .phpstorm.meta.php
and _ide_helper.php
files will be generated and should be added to your .gitignore
as you don't want to commit these.

- 17,074
- 5
- 83
- 129
-
Nice. Thank you very Much. Please can you explain me why I am not using facades? All the time I heard that this way is of ;using facades; : – Krystian Polska Jul 26 '17 at 18:13
-
@KrystianPolska I updated the answer to add additional information on facades. – Emile Bergeron Jul 26 '17 at 18:22
-
OP is not using Facades but magic methods on models, in his particular case, just using `::query()->whereIn` would have solved the problem – Tofandel Dec 13 '21 at 14:59
-
@Tofandel I already acknowledged that OP is not using facades but the trick to fix warnings is still relevant (or was still relevant at the time, it might have changed in the last 4 years, I don't work with Laravel anymore). – Emile Bergeron Dec 13 '21 at 18:00
-
@Tofandel my answer addresses warnings on magic methods and additional information on what facades actually are. You can see it was relevant to OP by the checkmark beside the answer, where I suggest a fix for the warnings inside PhpStorm. I believe the fix works regardless of if the magic methods were used on facades or not and that, at least at the time this question was asked, using `::query()` would probably had triggered the same warnings. – Emile Bergeron Dec 13 '21 at 22:12