I wrote a "Helper" controller that I want to use in other controllers, but I am doing something wrong. Is Lumen Service what i need? Then I just don't get how to set it up.
My main class:
namespace App\Http\Controllers;
use App\Http\Controllers\HelperController as Helper;
class InitController extends Controller
{
public function work($hash, $type)
{
return response()->json([
'answer' => Helper::makeCodeUrl()
]);
}
}
Helper controller:
namespace App\Http\Controllers;
class HelperController extends Controller
{
public function makeCodeUrl($arr, $type){
return str_random(32);
}
}
Looks like a huge copy and paste error to me. You are trying to call a non static method statically. That will not work. If you want to make this work you need to add the keyword "static" to your method head:
public static function makeCodeUrl(){
You should remove the parameters $arr and $type if you don't need them.
What you are trying to do is a pretty bad design. You should create a service class like UrlService for you url related methods and inject it into the controller.