Call a method from one controller inside another

前端 未结 2 1383
感动是毒
感动是毒 2021-01-12 04:46

Is it possible to call a method from one controller inside another controller in Laravel 5 (regardless the http method used to access each method)?

2条回答
  •  灰色年华
    2021-01-12 05:29

    This is how I have done it. Use the use keyword to make the OtherController available. Then you can call a method from that class on instantiation.

    method();
        }
    }
    

    Also check out the concept of a Command in Laravel. It might give you more flexibility than the method above.

提交回复
热议问题