4

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?

2 Answers 2

12

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer, How should I then call the view?
Yes using view('theview') should work, how exactly is it not working?
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

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.