I'm trying to create a Helper class using the Lumen Framework, but it's not working.
Files Structure
composer.json ./composer.json
[...]
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/",
"App\\Libraries\\": "app/Libraries"
}
},
[...]
Controller that is calling to the Helper Class ./app/Http/Controllers/UserController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use \Libraries\Helpers;
class UserController extends Controller {
/**
* Show a list of all of the application's users.
*
* @return Response
*/
public function index() {
return Helpers::test();
}
}
Helper Class ./app/Libraries/Helpers.php
<?php
namespace App\Libraries;
class Helpers {
public function test() {
return "test";
}
}
Calling the UserController@index ./routes/web.php
[...]
$router->get('/', 'UserController@index');
[...]
Error in route
Whoops, looks like something went wrong.
I'm trying everything but the Helper class are not working.
public function test() {
define your method as static (public static function test() {
) when you want to call this method as static – CodyKL