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
CodePudding user response:
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.