3

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?

Mister Verleg
  • 4,053
  • 5
  • 43
  • 68

2 Answers2

11

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.

Harry
  • 2,429
  • 4
  • 21
  • 26
4

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

zaffar
  • 679
  • 6
  • 13