How to print out value on controller Laravel?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company

Debugging a Laravel application involves printing out values on the controller, which is often required when you want to monitor specific data or test your code's logic. Luckily, there are multiple ways to achieve this within Laravel. In this comprehensive tutorial, we'll explore different approaches for debugging values in controllers and provide relevant examples.

Dumping Values with dd()

class TestMeController extends Controller {
    public function callMe($id)
    {
        $params = Request::all();

        dd($params);
    }
}
The dd() function, short for "die and dump," is a helpful tool for debugging in Laravel. It not only prints the specified variable value but also halts your application's execution to inspect it further. After executing this code, you will see the entire request collection displayed on your console.

Using dump() and Continuing Execution

class TestMeController extends Controller {
    public function callMe($id)
    {
        $params = Request::all();

        dump($params); // No pause, just logs to the console

        echo "This will continue running after logging data";
    }
}
If you don't want your application's execution paused while debugging, use dump(). It works similarly to dd(), but it doesn't halt the program. You can still see the output in the console and continue working on your code.

Logging Values via Console or Browser

Another method for debugging values is through logging them to the console or browser. This can be useful when you need to store debug information temporarily for future reference or just want to avoid cluttering up your controller with too many print statements.
class TestMeController extends Controller {
    public function callMe($id)
    {
        $params = Request::all();

        // Logging to console
        Logger::info("Params: " . json_encode($params));

        // Logging to browser
        echo "
" . print_r($params, true) . "
"; } }
In this example, we log the request collection's JSON representation using json_encode() for both console and browser output. For more advanced logging options like storing data in files or database tables, you can check out Laravel's documentation on logging (https://laravelcompany.com/docs/6.x/logging).

Using Log::debug() for System-wide Logging

Sometimes, you may need to log specific debug information for your entire application instead of just a controller's execution. For this, Laravel provides the Log facade.
class TestMeController extends Controller {
    public function callMe($id)
    {
        $params = Request::all();

        Log::debug("This is a debug log message: " . json_encode($params));
    }
}
By calling Log::debug(), we can store the logs associated with this controller method in Laravel's debug file, which allows us to view and analyze them later on. This is especially useful for large applications with many controllers that require individual debugging.

Conclusion

Debugging values in a Laravel application can be achieved using various methods, such as pausing execution with dd(), dumping without stopping your program with dump(), logging data to the console or browser, and system-wide logging through the Log facade. Each approach has its advantages depending on your specific needs, so pick the one that best fits your situation. Remember to always clean up and remove unnecessary debugging code once you're done with it to maintain a tidy application.