Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 445
Mister Verleg Avatar asked Sep 14 '25 16:09

Mister Verleg


2 Answers

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.

like image 109
Harry Avatar answered Sep 17 '25 06:09

Harry


Absolutely spot on! Just in the Laravel 6.0

'paths' => [
        resource_path('views'),
        resource_path('views/canaanmodels'),
    ],

Where my view is in the folder 'canaanmodels' which is inside 'views' floder and the realpath has now been replaced with resource_path and there is no more base_path... Hope it gonna help someone! Cheers

like image 29
zaffar Avatar answered Sep 17 '25 05:09

zaffar