Access Controller method from another controller in Laravel 5

Access Controller method from another controller in Laravel 5

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Why You Shouldn't Directly Call Controller Methods

When you have SubmitPerformanceController and PrintReportController, it might seem convenient to call the getPrintReport method directly from within the logic of the first controller. While this approach works in a vacuum, it violates the core architectural principles that keep Laravel applications maintainable as they scale. Directly invoking another controller's public methods creates tight coupling between business logic layers that should remain decoupled.

In a standard MVC architecture, controllers are responsible for handling HTTP requests and rendering responses. They act as the interface between the user (or API client) and the application's internal logic. When SubmitPerformanceController calls getPrintReport, you are effectively treating PrintReportController not as a separate entity managing its own lifecycle, but as a static utility class owned by the first controller. This makes refactoring difficult. If you later decide to move the report generation logic into a service or change the HTTP routing for PrintReportController, every instance of that direct call breaks your codebase.

The Recommended Approach: Service Classes

The cleanest solution is to extract the shared logic into a dedicated class, typically named after its responsibility rather than the controller it originally lived in. Let's assume the logic inside getPrintReport handles data retrieval and formatting for a report. You should move this implementation into a ReportService or simply ReportGenerator.

// app/Services/ReportService.php

namespace App\Services;

class ReportService
{
    public function getPrintReport($data)
    {
        // Original logic from PrintReportController::getPrintReport
        // ... implementation details ...
        
        return $this->formatDataForPrinting($data);
    }

    private function formatDataForPrinting($data)
    {
        // Formatting logic
        return ['header' => 'Performance Report', 'content' => $data];
    }
}

Once the logic resides in ReportService, both controllers can utilize it without knowing about each other. This is achieved through dependency injection, usually via the Service Container or constructor injection.

In your SubmitPerformanceController:

use App\Services\ReportService;

class SubmitPerformanceController extends Controller
{
    protected $reportService;

    public function __construct(ReportService $reportService)
    {
        $this->reportService = $reportService;
    }

    public function submit()
    {
        // Logic to process submission
        $reportData = ['status' => 'submitted', 'timestamp' => now()];
        
        $formattedReport = $this->reportService->getPrintReport($reportData);
        
        return view('performance.submitted')->with('report', $formattedReport);
    }
}

This pattern ensures that SubmitPerformanceController depends on the capability of generating a report, not on the specific implementation details of PrintReportController. It adheres to the Single Responsibility Principle, allowing each component to focus on its specific domain.

Handling HTTP Lifecycle Concerns

A common pitfall arises if you attempt to call methods that rely heavily on the HTTP request context (e.g., $request, $response) or try to trigger an actual HTTP redirect within a controller method called from another. Controllers are tightly bound to the request-response cycle; they expect to receive a Illuminate\Http\Request and return a Illuminate\Http\Response.

If getPrintReport in your original setup performed a redirect or accessed route-specific data, moving that logic directly into a service class requires careful refactoring. You cannot pass an entire HTTP Request object into a service easily without bloating the service interface. Instead, extract the pure business logic—the data transformation and calculation—and keep the request/response binding strictly within the controller.

If you absolutely must call a method from another controller (which is generally discouraged), you are essentially breaking the MVC pattern. You would be calling App\Http\Controllers\PrintReportController::getPrintReport($params). While this technically executes, it mixes concerns: one controller is now acting as a facade for another's specific HTTP endpoint logic. This leads to "spaghetti code" where testing becomes a nightmare because you cannot unit test SubmitPerformanceController in isolation without mocking the entire PrintReportController class and its dependencies.

Conclusion on Architecture

The decision to extract shared logic into a service layer pays dividends when debugging, testing, and extending functionality. If your getPrintReport method grows complex over time, having it isolated in a service makes that complexity visible only where it belongs. By keeping controllers thin and focused solely on routing data to views or API responses, you ensure that your application remains robust against the inevitable changes required in larger systems.

Our network