I'm trying to build a class with some frequently used functions that I can use from anywhere in my project. I don't know where to build the PHP file with the classes in it or how to recall them... Can anyone help me figure out where all this stuff fits in? THANKS!!!
/App/Http/Helpers/MyClasses.php
<?php
class PopularFunctions {
public function sayhi() {
echo 'hi';
}
}
?>
/App/Http/Controllers/TasksController.php
<?php
namespace App\Http\Controllers;
use App\Http\Helpers\MyClasses;
class TasksController extends Controller {
public function index() {
$myfunctions = new PopularFunctions();
$myfunctions->sayhi();
}
}
This returns: Class 'App\Http\Controllers\PopularFunctions' not found.
app
directory. There's no real restrictions. If you post your code and structure etc. we might be able to help you pinpoint the problem. – MateriApp
and is under theapp
folder so as long as you follow the standard and place your files underapp
they should be picked up. If not trycomposer dump-autoload
to re-create the autoload file – Dan