How to resolve call to undefined function?

Hi, was hoping that someone here could help me resolve this error:
production.ERROR: Call to undefined function App\Services\addAsset() {“userId”:3,“exception”:"[object] (Error(code: 0): Call to undefined function App\Services\addAsset() at /www/app/Services/CharacterManager.php:2480.

The code portion in question looks like this:

$userAssets = createAssetsArray();
$characterAssets = createAssetsArray(true);
            if(isset($data['stack_id'])) {
                foreach($data['stack_id'] as $stackId) {
                    $stack = UserItem::with('item')->find($stackId);
                    if(!$stack || $stack->user_id != $request->user_id) throw new \Exception("Invalid item selected.");
                    if(!isset($data['stack_quantity'][$stackId])) throw new \Exception("Invalid quantity selected.");
                    $stack->update_count += $data['stack_quantity'][$stackId];

                    addAsset($userAssets, $stack, $data['stack_quantity'][$stackId]);

The line that’s erroring is specifically the “addAsset($userAssets, $stack, $data[‘stack_quantity’][$stackId]);” part. As I’m pretty new to coding php, unfortunately I’ve not been able to understand what’s going on here, and resolving this issue on my own has proven to be an impossibility. If anyone could please help walk me through how to fix this, that would be greatly appreciated. If more information is needed, I’d be happy to provide that too. Thanks in advance!

So it’s probably not entirely helpful to say this, but… the problem is that you havent defined an addAsset function in your App\Services class.

So… the remedy to that is to define one. (or, if its not your class… figure out what function you were SUPPOSED to use)


Actually, this helped a lot, so thanks for calling this to my attention. Essentially, I didn’t realize that there was supposed to be something like this (the code is one that someone else built for free use and then I’ve altered for customization). So in going through the files, I found where that function was defined, and realized there was a missing }. Once again, thank you so much for the response, the problem has now been fixed.

1 Like