Creating Views in laravel

In Laravel Views contain the HTML served by your website and separate your controller / application logic from your presentation logic. Views are stored in the resources/views directory. A simple view might look something like this.

Step 1 : View stored in resources/views/demo.blade.php

<html>
   <body>
      <h1>Hello World!</h1>
   </body>
</html>

Step 2 : Add the following line in app/Http/routes.php file to set the route for the above view.

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

Step 3 : Let us execute this example by the following URL in the browser. This URL may be different based on your website.

http://localhost/blog/demo

Determining If A View Exists

If you need to determine if a view exists, you may use the View facade. The exists method will return true if the view exists:

use Illuminate\Support\Facades\View;

if (View::exists('emails.customer')) {
    //
}

Passing Data To Views

As you saw in the previous examples, you may pass an array of data to views

return view('demo', ['name' => 'abc']);

When you passing information in this manner, the data should be an array with key / value pairs. Internal your view you can then access each value using its corresponding key, like <?php echo $key; ?>. As alternative to passing a complete array of data to the view helper function, you may use the with method to add individual pieces of data to the view:

return view('demo')->with('name', 'abc');