0

My project is a Laravel project

If I have used psr-4 autoloading e.g.

"psr-4": { 
    "Admin\": "app/www/admin" 
 }

it works and routes properly to make views inside controllers I use the addNamespace:

View::addNamespace('admin', 'app\www\Admin\views'); 
return View::make('admin::dashboard');

this works but is there anyway to make the views accessible in the config somewhere? and if so can someone show me an example.

I guess the result I am looking for is like this:

View::make('admin.dashboard');

Thanks so much

Aiden

1 Answer 1

1

If I understand correctly, you want Laravel to look into multiple folders instead of just the default /app/views/ folder.

If that is the case, you can set it in the configuration:

// /app/config/view.php
'paths' => array(__DIR__.'/../views', __DIR__.'/../../admin/views'),

// Using it
View::make('admin.dashboard'); // Look into www/admin/views/admin/dashboard.blade.php

This is not really tested but hopefully pointing you to the right solution. The caveat is that you have another admin folder in there (following laravel view folder structure)

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

3 Comments

yeh cool so how would i then call a typical view View::make('admin.dashboard') or View::make('dashboard') ?
OKOK It's working but what if i have the same filename e.g. /admin/views/dashboard.php and /public/views/dashboard.php and i add both these to the app/config/view.php how does it differentiate?
Cool, was updating my answer, but glad you got it working. I believe the array order matter, in my answer it'll look into laravel default folder first. If you want it to scan your admin folder first, set it as the first value, instead of the second.

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.