dongyuan7981 2017-12-01 08:35
浏览 118
已采纳

Laravel在同一个控制器中执行多个功能

Is it possible to execute multiple functions in the same controller with one route. I thought it would be something like this but it doesn't work.

Route::get('getdata','controller@getData', 'controller@getData1', 'controller@getData2');

In the controller are these functions:

  • getData
  • getData1
  • getData2

Or is there a easier way?

  • 写回答

2条回答 默认 最新

  • dongzou3751 2017-12-01 08:45
    关注

    In the controller

    Add something like this.

    class YourController extends Controller {
        //...
    
        protected function getAllData() {
            //Executes the seperate functions.
            $this->getData();
            $this->getData1();
            $this->getData2();
        }
    
        //...
    }
    

    This will execute the functions respectively.

    Then from your route, you just call YourController@getAllData as the function of the controller.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动
  • ¥15 大一C语言期末考试,求帮助🙏🙏
  • ¥15 ch340驱动未分配COM
  • ¥15 Converting circular structure to JSON
  • ¥30 Hyper-v虚拟机相关问题,求解答。
  • ¥15 TSM320F2808PZA芯片 Bootloader