2

I want to use a helper functions but I got this error in my view :

Call to undefined function createSubCategories()

path of my helper functions:

Http\Controllers\Utilities\Helpers.php

my hlper :

<?php
namespace App\Http\Controllers\Utilities;


    function createSubCategories($parent_cat_id = 0)
    {

        $subs = DB::table('categories')->where('parent_cat_id', '=', $parent_cat_id)->get();
        if (count($subs) > 0) {
            echo '<ul>';
            foreach ($subs as $sub) {
                echo '<li>' . $sub->title_fa;
                echo $this->createSubCategories(($sub->id));
                echo '</li>';
            }
            echo '</ul>';
        }
    }

in composer.json :

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    },
    "files":
    [
        "app/Http/Controllers/Utilities/Helpers.php"
    ]
},

I used composer dump-autoload.

my view:

{{createSubCategories(0)}}

3 Answers 3

4

solved:

I just removed the namespace :

namespace App\Http\Controllers\Utilities;
Sign up to request clarification or add additional context in comments.

Comments

1

I could reproduce your problem and the solution is to leave out the line

namespace App\Http\Controllers\Utilities;

in your Helpers.php

Comments

1

I have faced same problem that you have mentioned above. in my composer.json, I did not integrate the helper functions. By integrating in composer.json->autoload->files, now it is ok.

 "autoload": {
 "files":[
 "app/Helper/setting.php"
  ]
  }

if your path is alright then it will be ok. For Every change of your helper function you must run the command composer dump-autoload.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.