# Views
To learn in detail about Views, you can visit the Laravel documentation here (opens new window).
# Directory Structure
Create a
Resources
folder in thepackages/Webkul/Blog/src
path. Inside theResources
folder, create another folder namedviews
. Now, inside theviews
folder, we need to create two folders, namelyadmin
andshop
. Finally, we need to create two more folders, namelydefault
andvelocity
, under theshop
folder. The updated directory structure will look like this:└── packages └── Webkul └── Blog └── src ├── ... └── Resources └── views ├── admin └── shop ├── default └── velocity
The default and velocity folders
Whenever you create a Blade file for the shop front, you need to keep the same file in both the
default
andvelocity
folders. This is because we are using thetheme
middleware. When we use thedefault
theme, the files will be called from thedefault
folder, and when we use thevelocity
theme, the files will be called from thevelocity
folder.WARNING
In this tutorial, we are using the
theme
middleware and thevelocity
theme. Therefore, it is necessary to keep the files in thevelocity
folder. However, if we are not using thedefault
theme, it is not necessary to keep the same files in thedefault
folder.Inside each folder,
admin
andvelocity
, create a file namedindex.blade.php
and add some HTML to it.└── packages └── Webkul └── Blog └── src ├── ... └── Resources └── views ├── admin │ └── index.blade.php └── shop ├── default └── velocity └── index.blade.php
admin/index.blade.php
<h2>Blog Admin Page</h2>
shop/velocity/index.blade.php
<h2>Blog Shop Page</h2>
# Load Views from Package
Now, we need to register our views in the service provider's
boot
method. Open the filepackages/Webkul/Blog/src/Providers/BlogServiceProvider.php
and update it as follows:<?php namespace Webkul\Blog\Providers; use Illuminate\Support\ServiceProvider; class BlogServiceProvider extends ServiceProvider { /** * Bootstrap services. * * @return void */ public function boot() { //... $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'blog'); } }
Now, check the routes in your browser.
Shop Output
Admin Output