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条)

报告相同问题?