Laravel, Composer: File autoload not working

Viewed 3190

I use Laravel 5.4 and want to autoload a helpers.php file with helper functions that I want to use all over my project (but especially in my controllers).

My composer.json looks like this:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7"
    },
    "autoload": {
        "files": [
            "app/Http/helpers.php"
        ],
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "files": [
            "app/Http/helpers.php"
        ],
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

My helpers.php looks like:

<?php
namespace App\Http;

function combineColumnNameType($columnLabels, $columnTypes) {
    $combined = [];
    // logic
    return $combined;
}

My problem is, that when I try to use a function of helpers.php in one of my Controllers it throws the following error message:

Call to undefined function App\Http\Controllers\combineColumnNameType()

I tried to composer dump-autoload a couple times, but it's not helping.

I also tried composer update.

What is the problem?

1 Answers
Related