DEV Community

Tutsmake
Tutsmake

Posted on

Laravel 10 Call/Access Controller Method from Another Controller

If you want to access some method from another controller in laravel 10 apps, you can use the app() helper method to get the other controller instance and then call the method from the instance.

Laravel 10 Call/Access Controller Method from Another Controller

In Laravel 10, you can call a controller method from another controller by:

  • Using the app() helper method to get the other controller instance.
  • Including the controller with the required method in the controller that needs to access it.
  • Using the syntax (new OtherController)->method().

For example, if you have a PostController and want to get the specialPostID() method, you can use the app() helper method to get the other controller instance and then call the method from the instance.

Read More Laravel 10 Call/Access Controller Method from Another Controller

Top comments (0)