I'm getting this same issue although my function lives in a helpers.php file. You could try removing from a class and place the function in a single file.
Call to undefined function - missing something?
Hi, I've been out of the industry for 10 years to raise my son and recently have just jumped back in - so I'm trying to catch up quickly (my previous experience was mostly databases so coding theory is ‘ok’ / syntax still weak). I'm missing something really simple and just can't figure it out - can you point me in the right direction / laracast - it's probably something I've forgot to setup...
I have several controllers that need to call the same code - it is string manipulation / business logic that does not require any data references (so I did not extend anything). I've placed it into its own directory under App\BusinessName (as just a simple class).
namespace App\BusinessName;
class Overlays
{
public function BuildDirectionLabels($compassrotate)
{
$directionlabels = ["spaceholder", "S", "W", "N", "E"];
// other logic
return $directionlabels;
}
}
In my controllers I have:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Location;
use App\BusinessName\Overlays;
class saveController extends Controller
{
public function index(location $location)
{
$directionlabels = \BuildDirectionLabels($location->compassrotate);
//other logic
}
}
And I’ve also added it to my composer.json and reloaded everything.
"autoload": {
"classmap": ["database"],
"psr-4": {"App\\": "app/"},
"files": ["app/BusinessName/Overlays.php"]
},
I keep getting
FatalErrorException in saveController.php line 18:
Call to undefined function BuildDirectionLabels()
Any ideas – what else did I forget to setup – do I need to place something into the AppServiceProvider, config files etc?
Change your overlays class into a Trait.
Then you should be able to do something like this...
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Location;
class saveController extends Controller
{
use App\BusinessName\Overlays;
public function index(location $location)
{
$directionlabels = $this->BuildDirectionLabels($location->compassrotate);
//other logic
}
}
Please or to participate in this conversation.