How to call the method of another controller in the method of laravel, calling dynamically

1. Now there are two controllers under two folders. A _ method

2. Because in the business, according to the conditions, the methods of different controllers are called, for example:

$temp;
if(true){
    requre_once($temp."Controller.php");
    (new $temp())->index();
}

are there any methods or features based on the laravel framework to call? Make it elegant. I seem to remember that the thinkphp3.2 framework has an R function.

Mar.04,2021

Why not write it in the model? As a matter of fact, there is no difference between the R method and the D method, so the parameter passing method is different. I am more curious about whether laravel has hook functions. Both yii and tp have


.

requirement realization:

if (true){
    app(B::class)->functionName();
}

but now that you mention the word elegance , the idea of calling another controller method in one controller is very inelegant , and even elegant implementations don't have elegant code

.
because methods of different controllers are called according to conditions in the business

you can post specific business needs so that you can help you solve the fundamental problems


the current framework does not call another controller, in one controller, and now files are used in the namespace, no area using require,. To achieve your goal, create a service, and call the method under the service you wrote in controller. The use of the file path can be called by injection using namespace,.


(new \namespace\B())->index();
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3617e-4d684.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3617e-4d684.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?