How to create view page in Laravel

How to create view page in Laravel 8

Posted by Luke Beeno on May 11, 2022

How to create view page in Laravel

How to create view page in Laravel 8

Posted by Luke Beeno on May 11, 2022

In this tutorial you will be shown how to create a view page. Laravel 8 will be used to demonstrate this task.

Step 1. Create a Controller called BlogController by running command

php artisan make:controller BlogController

Step 2. Create blade file

Go to resources\views and create file blog.blade.php

Step 3. Edit blog.blade file

<h1>Blog page</h1>

Step 4. Create index method in BlogController

Go to app\Http\Controllers\BlogController.php and edit file as below:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class BlogController extends Controller
{

    public function index()
    {
        return view('blog');
    }
}

Step 5. Create route

Go to routes\web.php and add line below:

Route::get('/blog', [BlogController::class, 'index']);

Once you start the server and go to url http://localhost:3000/blog or http://localhost/thenameofyourproject/public/blog, you should see the page.

This field is required
Your question have been successfully submitted and will be reviewed before published
Please login to ask a question