That happens to me when I am using https://github.com/barryvdh/laravel-ide-helper
PhpStorm warning: Multiple definitions exists for class ...
I am getting warnings with Classes like Model, Controller
https://dl.dropboxusercontent.com/u/60672885/warning.png
Is there a way to fix this?
Using PhpStorm 8
So without this package you do not get the warnings?
Found the solution. I can't explain it, but when i exclude the storage folder in Settings/Directories this warning goes away!
This is old but here's a way to figure this out. On the class with multiple definitions hit CTRL+B to get a list of the definitions available. Now you see who's competing with each other. In my case it was ide-helper vs some classes in codeception. I just went to the project settings and excluded the codeception vendor dir.
I've the same problem using Laravel 5 and both seems to be important.
Model .../vendor/laravel/framework/src/Illuminate/Database/Eloquent
Model .../storage/framework/compiled.php
@kontrast You don't want the storage folder to be indexed by your IDE, exclude it.
@JarekTkaczyk Thanks for the quick answer. The warning disappears but it didn't solve my problem. I haven't put "namespace App;" in my own class cause it isn't in the L5-from-scratch tutorial either. After doing that everything is working.
so the explanation is that laravel/composer is able to generate a compiled.php file that puts all of your class definitions into one big file that can help with load times (not always true). this is another option in addition to autoloading (with something like PSR-0 or PSR-4). because this compiled.php file exists, all of your classes are technically defined twice (although the definition is the same). this confuses phpstorm, so all you need to do is 'exclude' the compiled file from PHPStorm's indexing. depending on which version of laravel you use, this may be in different places, including bootstrap/cache for 5.1 and storage/framework for 5.0.
+1 @browner12 - it's simply that you have run php artisan optimize or something similar and debug is false.
This creates the compiled.php file, however this can be ignored by your IDE.
To test this you can run php artisan clear-compiled and see the difference.
Note: I resolved this by going to Preferences-> Languages & Frameworks-> PHP; and then under Include path, remove the conflicting path. (In my case a package reference in the vendor directory to a package I was developing inside my Laravel project)
@ALEXMAN - I went and looked and I had piles of includes from something like 5 laravel projects ago! Bizarre!
Just had the same issue while upgrading from Laravel 9 to 10. The IDE was complaining about multiple definitions in several files. My solution was to delete _laravel_idea from the vendor directory.
composer require --dev barryvdh/laravel-ide-helper
php artisan ide-helper:generate
Optionally, you can also generate PHPDoc blocks for models:
php artisan ide-helper:models
It's harmless, so you can ignore it.
Let's distinguish between "just a warning in the IDE" and "my code mistake".
You can ignore "just a warning in the IDE".
If you really want to solve it, add the -M option.
php artisan ide-helper:models -M
https://github.com/barryvdh/laravel-ide-helper#automatic-phpdocs-for-models
Please or to participate in this conversation.