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

gitwithravish's avatar

What could be an easy way to see .php file output in terminal?

Many a times, I quickly wish to create laravel project and quickly use some in-built classes to perform some calculations.

In order to see the output, what I tend to do is,

  • create a route
  • write my logic within it
  • access it using browser to print output and check my logic.

Is there any way to just get the output in terminal ?

Note: I could use plain php but sometimes I need to access vendor files of laravel framework. That is why I am looking for a specific solution to my problem.

0 likes
7 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Did you try tinker?

php artisan tinker
1 like
rodrigo.pedra's avatar

I use tinker a lot to "tinker" with my code.

But sometimes when I want to test a longer script using my app's classes and Laravel goodies I often add a command to the ./routes/console.php file:

// ./routes/console.php

Artisan::command('app:test', function () {
    $this->info('testing');
    
    // ... some code
});

And run it from the CLI:

$ php artisan app:test

Just to add another tool to your tool belt =)

EDIT fixed the path where you can define your artisan commands using the Artisan façade. Thanks @sinnbeck for the heads up.

1 like
Sinnbeck's avatar

@rodrigo.pedra Did you bind that route yourself? As far as I know, laravel does not come with a routes/artisan.php file? Or did you mean routes/console.php ?

2 likes
rodrigo.pedra's avatar

Yes, I meant ./routes/console.php

It was a bit late down here, so it might have been wishful thinking... Thanks for the heads up!

I'll add a comment to that response for later reference.

1 like

Please or to participate in this conversation.