The basic example
Open routes/web.php
file and paste the following code in file:
Route::get('helloworld', function () {
return '<h1>Hello World</h1>';
});
here 'helloworld' will act as page name you want to access,
and if you don't want to create blade file and still want to access the page directly then you can use laravel routing this way
now type localhost/helloworld
in browser address bar and you can access page displaying Hello World.
The next step.
So you've learned how to create a very simple Hello World! page by returning a hello world sentence. But we can make it a bit nicer!
Step 1.
We'll start again at our routes/web.php
file now instead of using the code above we'll use the following code:
Route::get('helloworld', function() {
return view('helloworld');
});
The return value this time is not just a simple helloworld text but a view. A view in Laravel is simply a new file. This file "helloworld" contains the HTML and maybe later on even some PHP of the Helloworld text.
Step 2.
Now that we've adjusted our route to call on a view we are going to make the view. Laravel works with blade.php files in views. So, in this case, our route is called helloworld. So our view will be called helloworld.blade.php
We will be creating the new file in the resources/views
directory and we will call it helloworld.blade.php
Now we'll open this new file and edit it by creating our Hello World sentence. We can add multiple different ways to get our sentence as in the example below.
<html>
<body>
<h1> Hello World! </h1>
<?php
echo "Hello PHP World!";
?>
</body>
</html>
now go to your browser and type your route again like in the basic example: localhost/helloworld
you'll see your new created view with all of the contents!