1

I'm trying to build a saas application (saas here means software as a service) in laravel 5.3. I'm trying to implement the view folder destination by extending the ViewServiceProvider. For example I'm having two different themes for two different domains. I'm having the set of HTML code in views in different folders, something like this:

View
----| Theme One
--------| Navbar
--------| Sliders
--------| Tabs
--------| Parallax
--------| Iconbox
--------| template.blade.php
----| Theme Two
--------| Navbar
--------| Sliders
--------| Tabs
--------| Parallax
--------| Iconbox
--------| template.blade.php

Now I want to define folder structure dynamically for these domains so that it should show the modules of their respective theme. Like suppose if I want to include sub-view of Navbar I just have to write

@include('Navbar')

and it should access the respective theme Navbar folder or sub-view. To implement this I'm extending the ViewServiceProvider and in config/app.php I'm just commenting out the ViewServiceProvider and added the WebViewServiceProvider which I made, it is not setting the destination, here is my code:

namespace Nitseditor\System\Providers;

use Illuminate\View\FileViewFinder;
use Illuminate\View\ViewServiceProvider;
use Nitseditor\System\Models\Domain;

class WebViewServiceProvider  extends ViewServiceProvider
{


    /**
     *  Register View Folder
     *
     * @return void
     */
    public function registerViewFinder()
    {

        $this->app->bind('view.finder', function ($app) {
            $paths = $app['config']['view.paths'];

            $http_req = php_sapi_name() == 'cli' ? 'noetic.com' : $this->app['request']->server('HTTP_HOST');
            $domainName = explode(":", $http_req)[0];
            $domain = Domain::where('domain_name', $domainName)->first();

            if($domain)
            {
                foreach ($domain->themes as $theme)
                {
                    $paths = 'Nitseditor\System\Resources\Views\Themes\\' . $theme->theme_name;
                }
            }

            return new FileViewFinder($app['files'], array(base_path($paths)));
        });
    }
}

My config\app.php looks like:

//        Illuminate\View\ViewServiceProvider::class,
Nitseditor\System\Providers\WebViewServiceProvider::class,

while executing and checking through controller I can see the destination paths of views are same as default

class DomainController extends Controller {

    public function checkDomain()
    {
        $app = App::make('config');
        dd($app);
    }
}

Views directory check

Edit

well I tried executing without conditional statements it happens to be same.

public function registerViewFinder()
{

    $this->app->bind('view.finder', function ($app) {

        $paths = 'Nitseditor\System\Resources\Views\Themes\Themeone';

        return new FileViewFinder($app['files'], array(base_path($paths)));
    });
}

Help me out with this.

Nitish Kumar
  • 6,054
  • 21
  • 82
  • 148
  • Can you verify that you're getting into `if($domain)`? – Ohgodwhy Jan 11 '17 at 03:57
  • @Ohgodwhy yes it is. I'm setting the database connection in the same way and it is coming up properly. Also I've executed `webDatabaseServiceProvider` in boot method rather than using register method. I think if I implement in boot method it will execute, but while doing so in `webViewServiceProvider` I get error. – Nitish Kumar Jan 11 '17 at 04:17
  • @Ohgodwhy well I tried executing without conditional statements and simply placing `$paths = 'Nitseditor\System\Resources\Views\Themes\Themeone';` and returning `return new FileViewFinder($app['files'], array(base_path($paths)));` it happens to be same. – Nitish Kumar Jan 11 '17 at 04:47

1 Answers1

0

Well I kept on trying to die dump the code and tried checking $app array. I guess when I try doing App::make::('config') laravel collects information from the configuration files and shows the configuration array of app in which dynamic configuration are not being displayed.

Then I simply tried checking my views:

return view('template');

It displayed the blade file/views exactly what I required, well it might help someone. Don't panic with

$app = App::make('config');
dd($app);

Cheers!!

Nitish Kumar
  • 6,054
  • 21
  • 82
  • 148