如何在Laravel 5中的另一个控制器中调用控制器功能 [英] How to Call a controller function in another Controller in Laravel 5

查看:605
本文介绍了如何在Laravel 5中的另一个控制器中调用控制器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用laravel 5.

im using laravel 5.

我需要调用一个控制器函数,但这应该在另一个控制器中完成.

I need to call a controller function but this should be done in another controller.

我不知道该怎么做

public function examplefunction(){

   //stuff

}

我为此功能设置了一条路线,

And i have a Route for this function, so at

public function otherfunctioninothercontroller(){
// I need examplefunction here
}

我该怎么做?

推荐答案

如果它们不在同一文件夹中,请将use namespace\to\ExampleClass;放在文件顶部,然后就可以实例化控制器.

If they are not in the same folder, place use namespace\to\ExampleClass; on top of your file, then you are able to instantiate your controller.

这篇关于如何在Laravel 5中的另一个控制器中调用控制器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆