Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

birbird's avatar

How to print something in Laravel console

It is quite convenient to see all logs in the console (php artisan serve) when developing, like Rails. Lavarel seems dont follow this way, the output in the console is not the logs.

Could anyone please tell what is the elegant way to print something in the development console. Any help will be highly appreciated!

0 likes
13 replies
birbird's avatar

@mikebronner, thanks a lot for your reply. Maybe I am wrong, but I think the http://laravel.com/docs/5.1/artisan#writing-output is for Artisan Command, not for my situation. When writing a Command which need to output something in the console while its executing, the above document helps, but I am not writing a Command, I want output something in controller, model or anywhere in the project.

usman's avatar

@birbird If you just want to write your own messages to the console you can just use the following code inside your route actions:

$output = new \Symfony\Component\Console\Output\ConsoleOutput(2);

$output->writeln('hello');

I thought you wanted to log the Exceptions as well :)

Usman.

5 likes
screwtape_mk's avatar

@birbird did u come right on this. I am also looking to output some variable(s) in my controller. But i want to do it on the console.

Snapey's avatar

@screwtape_mk you place dump() commands at strategic places in your code.

The output of the dump goes to your console instead of to the browser

eg

$countries = \DB::('AREAS');
dump($countries);

the dump is sent to the console. Your controller or whatever keeps running

Laravel artisan's tinker is a repl (read-eval-print loop) tool that allows you to type PHP commands and immediately get the result.

Not at all the same

1 like
Snapey's avatar

No. I said 'in recent versions' and linked to an article that says it was added to 5.7

tekknow's avatar

I tried this and still no output to the console.

tekknow's avatar

I briefly saw the output in the browser page, then it disappeared. How to send info to the browser console? In php it is usually echo "hello".

Sinnbeck's avatar

@tekknow you seem to be confused regarding the browser console. That is for Javascript. This talks about dumping data to the shell from where you started your server (artisan serve). If you are having issues consider creating a new tread describing your problem and what you are trying to do

Please or to participate in this conversation.