Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print messages on console in Laravel?

How do laravel print out some string on console when running php artisan serve? I tried Log::info but it isn't working.

like image 883
Tung Tse Avatar asked Feb 19 '17 06:02

Tung Tse


People also ask

What is DD in Laravel?

dd stands for "Dump and Die." Laravel's dd() function can be defined as a helper function, which is used to dump a variable's contents to the browser and prevent the further script execution. Example: dd($array);

What is Laravel console?

Laravel makes it very convenient to define the input you expect from the user using the signature property on your commands. The signature property allows you to define the name, arguments, and options for the command in a single, expressive, route-like syntax.

What is tinker in Laravel?

Laravel Tinker allows you to interact with a database without creating the routes. Laravel tinker is used with a php artisan to create the objects or modify the data. The php artisan is a command-line interface that is available with a Laravel. Tinker is a command tool that works with a php artisan.


2 Answers

You can call info() method

   $this->info("Your Message");

like image 74
Akash Kumar Verma Avatar answered Sep 22 '22 07:09

Akash Kumar Verma


Laravel 5.6 simplified this because you now have a logging.php config file you could leverage.

The key thing to know is that you want to output to stdout and php has a stream wrapper built-in called php://stdout. Given that, you could add channel for that wrapper. You would add the stdout "channel" to your channels that you will be logging to.

Here's how the config will basically look:

<?php    

return [
  'default' => env('LOG_CHANNEL', 'stack'),

  'channels' => [
    'stack' => [
        'driver' => 'stack',
        'channels' => ['single','stdout'],
    ],

    'single' => [
        'driver' => 'single',
        'path' => storage_path('logs/laravel.log'),
        'level' => 'debug',
    ],

    'stdout' => [
        'driver' => 'monolog',
        'handler' => StreamHandler::class,
        'with' => [
            'stream' => 'php://stdout',
        ],
    ],
];

I have more information here - Laravel 5.6 - Write to the Console

like image 42
2upmedia Avatar answered Sep 24 '22 07:09

2upmedia