0

I have inherited some legacy code and I am trying to get it to work on a dev server. It works fine on the prod server. I am a laravel noob.

I have almost everything working. (I have locked all the versions in composer.json, to match the working site)

The last thing that is failing is this line :

<img src="{{ asset(GetProfilePicLanding())}}" class="img-responsive">

I get the errorCall to undefined function GetProfilePicLanding()

The blade file is in resources/views/index.blade.php

The function GetProfilePicLanding() is in app/helper.php

I can not imagine why the two servers running same code would be different in finding this file

I was looking at adding something like @include('app/helper') but then i have to modify the conf/view file.

I am trying not to modify the code itself if possible from prod.

Would love any ideas or how best to debug this.

thanks for any help

randy
  • 1,685
  • 3
  • 34
  • 74
  • try running php artisan config:cache . The above requires a change to app/config, any changes to config, this artisan command usually needs a run after changing. Explanation here: https://stackoverflow.com/questions/44021662/how-to-create-global-function-that-can-be-accessed-from-any-controller-and-blade – Paul Stanley Jun 05 '21 at 20:47

1 Answers1

1

Assuming your helper.php file looks something like this:

<?php

if (!function_exists('helper1')) {
    function helper1($string)
    {
        return ...;
    }
}

if (!function_exists('helper2')) {
    function helper2()
    {
        return ...;
    }
}

// and so on

You can add a line in your composer.json file to autoload it.

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

You might need to run composer update after this though.

IGP
  • 14,160
  • 4
  • 26
  • 43