laravellaravel-bladelaravel-views

Laravel view from different folder


I have a laravel project where I have the following view:

'ProjectName\custom\subfolder\resources\views\theview.blade.php'

How can I return this view?

I tried to use view('theview') That did not work because that only works on views inside:

 'ProjectName\resources\views'

How can I return the view from outside theresources\views folder?


Solution

  • Inside the config/view.php config file, add to the paths key:

    <?php
    
    return [
    
        'paths' => [
            realpath(base_path('resources/views')),
            realpath(base_path('custom/subfolder/resources/views')),
        ],
    
    
        'compiled' => realpath(storage_path('framework/views')),
    
    ];
    

    You can load your views in the usual way, eg view('my-view'), however duplicate names (or name collisions) will result in Laravel selecting the view based on the order specified in the paths key.