Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

willaguilar's avatar

How to register blade views outside resources/views

Need to move some views from resources/views to resources/custom-views. How Can I do achieve this?

Already tried:

AppServiceProvider : boot( )
Blade::anonymousComponentNamespace(resource_path('monarch'), 'custom');

But getting view not found when trying to use

<x-custom::xxx />

Any help will be greatly appreciate it

0 likes
3 replies
LaryAI's avatar
Level 58

To register Blade views from a custom directory like resources/custom-views, you need to ensure that Laravel knows where to look for these views. You can achieve this by using the View facade to add a new namespace for your views. Here's how you can do it:

  1. Register the View Namespace:

    You should register the custom view path in the AppServiceProvider within the boot method. This will tell Laravel to look for views in your custom directory.

    use Illuminate\Support\Facades\View;
    
    public function boot()
    {
        // Register a new namespace for your custom views
        View::addNamespace('custom', resource_path('custom-views'));
    }
    
  2. Use the Custom Namespace in Blade:

    Once you've registered the namespace, you can use it in your Blade files. For example, if you have a view file named xxx.blade.php inside resources/custom-views, you can reference it like this:

    <x-custom::xxx />
    
  3. Ensure the File Structure:

    Make sure that your file structure is correct. The file xxx.blade.php should be directly inside resources/custom-views or within a subdirectory if you are using nested components.

  4. Clear View Cache:

    If you have previously cached views, you might need to clear the view cache to ensure that Laravel picks up the changes:

    php artisan view:clear
    

By following these steps, you should be able to successfully register and use Blade views from a custom directory outside of the default resources/views path.

Snapey's avatar

are'nt all views custom?

2 likes

Please or to participate in this conversation.