Console Usage
When developing with Laravel and Aventus, it’s often useful to log information directly to the PHP console (the same place where you run php artisan serve).
To make this easier, Aventus provides a lightweight utility class: Aventus\Laraventus\Tools\Console.
This helper lets you log messages, inspect variables, and trace function calls without breaking your HTTP responses, perfect for debugging API logic, models, or request data in real-time.
Overview
Section titled “Overview”Console works by temporarily capturing output (using ob_start / ob_get_contents) and sending it to error_log, which appears in the console or terminal running Laravel.
This allows you to safely call echo, var_dump, or debug_print_backtrace() inside a web request, without corrupting the JSON or HTML response.
Available Methods
Section titled “Available Methods”| Method | Description |
|---|---|
Console::log(string $text) | Prints a simple text message to the console |
Console::logError(Throwable $err) | Prints an error to the console |
Console::dump(mixed $data) | Dumps a variable’s content (like var_dump()) to the console |
Console::trace() | Displays a stack trace to help identify where the code was executed |
Example Usage
Section titled “Example Usage”use Aventus\Laraventus\Tools\Console;
class UserController extends Controller{ public function show(int $id) { $user = User::find($id);
Console::log("Fetching user with ID: $id"); Console::dump($user);
return new UserResource($user); }}Console output (visible in php artisan serve):
Fetching user with ID: 12object(App\Models\User)#123 (10) { ["id"]=> int(12) ["name"]=> string(4) "John" ["email"]=> string(17) "john@example.com" ...}Summary
Section titled “Summary”The Console class provides a safe and convenient way to print debug info while running Laravel in development.
It avoids breaking responses and lets you inspect backend logic in real time.
Works perfectly with controllers, models, or Aventus framework internals.
Configuration
Section titled “Configuration”The method logError will print the stack trace for the error. To limit the number of stack printed, the configuration file contains the parameter stack_limit :
<?php
return [ "error" => [ "stack_limit" => 10 ]];