Laravel Views

Manish Chaudhary
ISOP Nepal
Published in
1 min readMay 27, 2020

Views contain html code that is served by application as response. They are stored in resources/views directory. As laravel uses blade as templating engine. The view files are stored as extension .php prepended by .blade so the filename will look something like {viewname}/blade.php

We can check if view exists or not using following code.

if (View::exists('index')) {
//
}

We can pass data to view like this.

return view('index.blade.php', ['tasks' => $tasks]);

In some project we might need to share data to all views in our app. For that we add below code to the boot method of AppServiceProvider

public function boot()
{
View::share('key', 'value');
}

For more details on laravel views, visit the link https://laravel.com/docs/7.x/views

--

--

Manish Chaudhary
ISOP Nepal

Software developer and father to a beautiful daughter