How to create Custom View Namespaces in Laravel?

Harish Kumar · · 4131 Views

In Laravel, our view files are stored in the resources/views directory, which is a completely fine spot for them. However, maybe sometimes we have another area where we store our blade files close to the first one. Luckily, Laravel provides namespaced views that allow us to specify another location to load blade files. That is very useful if you are creating a Laravel package.

// Add the namespace and a path
View::addNamespace('namespace', '/path/to/other/views');

// And use it like always
view('namespace::admin.index');
view('namespace::posts.edit');
0

Please login or create new account to add your comment.

0 comments
You may also like:

Secure Your SPA with Laravel Sanctum: A Step-by-Step Guide

In today's web development landscape, Single Page Applications (SPAs) are increasingly popular. But securing their interaction with backend APIs is crucial. Laravel Sanctum provides (...)
Harish Kumar

Multi-Authentication with Guards in Laravel

Laravel's robust authentication system provides a powerful mechanism for securing your application. To cater to scenarios where you need different user roles with distinct login (...)
Harish Kumar

Laravel Pint & VS Code: Automate Your Code Formatting

Laravel Pint is an opinionated PHP code style fixer built on top of PHP-CS-Fixer, designed to simplify the process of ensuring clean and consistent code style in Laravel projects. (...)
Harish Kumar

Laravel Clockwork: A Deep Dive into Debugging, Profiling Skills and Best Practices

In the world of web development, building complex applications often comes with the challenge of identifying and resolving performance bottlenecks. This is where a reliable debugging (...)
Harish Kumar

Effortless PDF Generation in Laravel: A Guide to Using Spatie/Browsershot Package

Looking to generate or export PDF files using Laravel? Look no further! In this article, we'll guide you through using the Laravel spatie/browsershot package to seamlessly convert (...)
Harish Kumar

Part #3: Rule objects based custom validation in Laravel

Laravel comes with multiple ways to add custom validation rules to validate form request inputs. I have already explained some of the ways in the following article links:
Harish Kumar