Intelephense cannot find a certain class in App/Helpers

95 Views Asked by At

I have created a class in App\Helpers\IdTransformer theres just two functions there.

I have registered it in aliases array in my app.php in config\app

'aliases' => Facade::defaultAliases()->merge([
        // 'Example' => App\Facades\Example::class,
        'IdTransformer' => App\Helpers\IdTransformer::class,
    ])->toArray(),

then i do, php artisan config:clear and php artisan config:cache

i can successfully access the file, in my code, but the Intelephense cannot find it. and it is so annoying. what must i do?

2

There are 2 best solutions below

0
Sina Nbxh On BEST ANSWER

If you want to use your favorite helper file in Laravel programs, you should put it in the composer.json file and provide autoload, please pay attention to the example below:

.
.
.
"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Factories\\": "database/factories/",
        "Database\\Seeders\\": "database/seeders/"
    },
    "files": [
        "app/Helpers/IdTransformer.php"
    ]
},
.
.
.

Add the following presentation to the ./composer.json file and in the autoload section:

        "files": [
        "app/Helpers/IdTransformer.php"
    ]

At the end type the following command:

composer update

In any part of your Laravel application, you can use the functions in IdTransformer.php as follows:

NameFunction();

At the same time, hit the command

0
Rex Zednelab On

What i did to solve this is,

I just put this line in the composer.json

"autoload": {
    "psr-4": {
        ...
        "App\\Helpers\\": "app/Helpers",
        ...
    }
},

then i run composer dump-autoload