How to create a new Blade view in Laravel



Image not found!!

In Laravel, Blade is the templating engine used to create views. Creating a new Blade view involves a few simple steps. Here's a step-by-step guide:

Step 1: Create a Blade View File

Create a new Blade view file in the resources/views directory. Choose a meaningful name for your view file and give it a .blade.php extension. For example, let's create a view file called newView.blade.php:

php
<!-- resources/views/newView.blade.php --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>New View</title> </head> <body> <h1>Welcome to the New View!</h1> </body> </html>

Step 2: Use the Blade View

Now that you've created the Blade view, you can use it in your routes or controllers. For example, if you want to return this view from a controller, you can do the following:

php
// app/Http/Controllers/YourController.php namespace App\Http\Controllers; use Illuminate\Http\Request; class YourController extends Controller { public function showNewView() { return view('newView'); } }

Step 3: Create a Route

Next, you need to create a route to access the view. Open the web.php file located in the routes directory, and define a route for your controller method:

php
// routes/web.php use App\Http\Controllers\YourController; Route::get('/new-view', [YourController::class, 'showNewView']);

Step 4: Access the View

Visit the URL associated with the route you created in your browser. In this example, it would be something like http://your-app-url/new-view. You should see the content of your newly created Blade view.

That's it! You've successfully created a new Blade view in Laravel and accessed it through a route. You can customize your Blade views with dynamic content, Blade directives, and more, based on your application's requirements.