How to use external function in php route

one text

Solution:

It wants a callback, so you need to pass a function itself. In your case using the parenthesis () invokes (calls) the function and returns the result of it instead of passing the function itself.

So here is a simple example of how you could do it:

Route::add('/', LoginController::login);

Wrapping it into a another function enables you to even pass arguments.

// shorthand function syntax since 7.4
Route::add('/', fn() => LoginController::login());

// example arguments (just a prototype)
Route::add('/', fn() => LoginController::login($username, $password));

or

Route::add('/', function() { LoginController::login() });

// example arguments (just a prototype)
Route::add('/', function() { LoginController::login($username, $password) });

Source