0

Am new to Laravel and i have been trying to create a helper function like i would in codeigniter within a demo package am currently developing. But, you know, being knew to the framework it seems a little bit hard to get that done as i have applied some helps i could find online to no avail.

My Directory Structure Looks like So:

Directory Structure

I have just one function in the app.php file

if (! function_exists('baxi_services')) {
    function baxi_services()
    {
       $data = ['web dev', 'web design', 'SEO'];

       return json_decode($data, JSON_PRETTY_PRINT);
    }
}

The composer.json file has these lines:

 "autoload": {
        "psr-4": {
            "Courage\\Baxi\\": "src/"
        },
        "files": [
            "src/helpers/app.php"
        ]
    }

And the problem is, when i call this function in my controller like so:

  return baxi_services(); 

i get the following Error:

Call to undefined function Courage\Baxi\Http\Controllers\baxi_services()

I have all ran composer dum-autoload command in my terminal but that doesnt solve the problem

courage
  • 115
  • 3
  • 20
  • Have look over here: https://stackoverflow.com/questions/28290332/best-practices-for-custom-helpers-in-laravel-5 – user3532758 Nov 24 '19 at 15:28
  • @user3532758 yea, – courage Nov 24 '19 at 15:30
  • @user3532758 i moved helper folder to the app directory and used the second solution provided here [link](https://stackoverflow.com/questions/28290332/best-practices-for-custom-helpers-in-laravel-5) and it worked but i really want the Helper folder to be within the package am developing – courage Nov 24 '19 at 16:11
  • @user3532758 any suggestion? – courage Nov 24 '19 at 16:12
  • Have a look at this link ;) https://stackoverflow.com/a/51322978/3532758 – user3532758 Nov 24 '19 at 17:06

0 Answers0