Skip to content

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.

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.

MethodDescription
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
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):

Terminal window
Fetching user with ID: 12
object(App\Models\User)#123 (10) {
["id"]=> int(12)
["name"]=> string(4) "John"
["email"]=> string(17) "john@example.com"
...
}

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.

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
]
];