In this example, we will see how to load a view using the Laravel Route::view() method in the Laravel 9 application. Assume If you are defining a route that is going to load a blade view, you may use the Route::view method. This method accepts two parameters. The first parameter is URI and the second parameter is the view. Let's see the example:

<?php

use Illuminate\Support\Facades\Route;

Route::view('/', 'welcome');

 

The above code is the same of below code:

<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return view('welcome');
});

 

We can also pass the with that view like:

<?php

use Illuminate\Support\Facades\Route;

Route::view('/welcome', 'welcome', ['name' => 'Laravelia']);

 

Read also: Laravel 9 Route Redirect Example

 

Hope it can help you.

Category : #laravel

Tags : #laravel , #laravel routing