Search code examples
laravelvscode-extensionsintelephense

Intelephense cannot find a certain class in App/Helpers


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?


Solution

  • 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