Support the ongoing development of Laravel.io →
Installation Configuration

I want to keep my backend (admin) separate from the rest of the app. I want to keep the admin controllers/configs/views/etc all in a single autoloader location, like app/Acme/admin

app/
|----Acme/
|----|----admin/
|----|----|----configs/
|----|----|----controllers/
|----|----|----|----AdminController.php
|----|----|----views/
|----|----|----|----index.blade.php
|----|----|----|----dashboard.blade.php
|----configs/
|----controllers/
|----|----HomeController.php
|----models/
|----views/
|----|----index.blade.php
|----|----foo.blade.php

Then autoload the whole Acme/admin domain with psr-4

// composer.json
"psr-4": {
    "Acme\\Admin\\": "app/acme/admin/"
}

If everything is properly namespaced with Acme\Admin all my classes should work fine. But where I'm confused is how to load view files that are outside of the standard 'app/views' folder. Since blade files are not classes that can be namespaced I'm not sure how to View::make() the 'index.blade.php' inside my Acme\Admin namespace versus the 'index.blade.php' in 'app/views'. I know that view files inside of packages are prefixed with the package, like View::make('package::foo.blade.php'). But I'm not sure how it works with my structure.

// HomeController.php
<?php
Class HomeController {
    public function getIndex() {
        View::make('index');
    }
}

// AdminController.php
<?php namespace Acme\Admin\Controllers;
Class AdminController {
    public function getIndex() {
        \View::make('index');
    }

    public function getDashboard() {
        \View::make('dashboard');
    }
}

Any help would be appreciated.

Last updated 3 years ago.
0

You should use:

View::addNamespace("backend", "path/to/backend");
View::addNamespace("frontend", "path/to/frontend")

You can put this on a service provider or in start.php file.

Then you can access to the proper view using:

return View::make("backend::auth.login"); //return path/to/backend/auth/login.blade.php

You should have the same problem with configuration, but you can resolve using

Config::addNamespace(); //works like View::addNamespace

Take a look at http://laravel.com/docs/packages

Last updated 3 years ago.
0

Thanks, that's exactly what I was looking for!

Last updated 3 years ago.
0

It works, but layouts doesnot

For example:

protected $layout = 'layouts.master';

/**
* Show the user profile.
*/
public function showProfile()
{
     $this->layout->content = View::make('user.profile');
}

protected $layout = 'layouts.master' searchs in app/views/layouts -directory instead of Acme/admin/views/layouts

Last updated 10 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

ammonkc ammonkc Joined 31 Jan 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.