How do I write to the console from a Laravel Controller?

You can use the Log facade to write to the console from a Laravel controller. Here's an example:


use Illuminate\Support\Facades\Log;

class MyController extends Controller
  public function index()
    Log::info('This is some useful information.');
    return view('welcome');

This will write the message 'This is some useful information.' to the console when the index method is called.

By default, the message will be written to the storage/logs/laravel.log file. You can customize the location of the log file by modifying the log option in the config/app.php file.

Alternatively, you can use the echo or print_r functions to write to the console, but the Log facade is a more flexible and powerful option.