1

so I am Laravel newbie. Basically, what I am trying to do is to view the "hello world" message when loading the Laravel default landing page. I have the following,

Route::get('/', function () {
    echo"hello world";
    return view('welcome');
});

But "hello world" is not showing up in the terminal. Is that even the proper use of echo in Laravel? Help will be appreciated.

Thanks

TechSelfLearner
  • 369
  • 1
  • 13

1 Answers1

2

Echo doesn't work like that. You want to show hello world text in your welcome file. Here are some things you might want to know. First, assign hello world string to a variable and pass it to the view like this.

Route::get('/', function () {
  $text = "Hello world!";
  return view('welcome', compact('text'));
});

And in your view file, pass this variable to some HTML tag like this.

<h1>{{ $text }}</h1>

Log is something else, it is for logging the output to a .log file which we can find in /storage/log. Also if you remove the return view statement from the function and instead of this return a direct hello world text it will show up in your browser screen.

Route::get('/', function(){
   return 'Hello World';
});

Hope this answers your question.

Hassan Malik
  • 130
  • 11
  • is there a way I can see the output in terminal? I come from node.js/django background where you can send output message that can be shown in terminal using ```console.log()```and```print()``` – TechSelfLearner Oct 11 '21 at 16:39
  • 1
    Yes you can, but that's a very different case with laravel console commands. Sadly laravel lacks what you're asking for. – Hassan Malik Oct 11 '21 at 16:44
  • [Console Commands](https://laravel.com/docs/8.x/artisan#writing-commands) here's the reference if you are interested in exploring it. – Hassan Malik Oct 11 '21 at 16:45