Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Models #58

Open
maganius opened this issue Jul 21, 2021 · 2 comments
Open

Models #58

maganius opened this issue Jul 21, 2021 · 2 comments

Comments

@maganius
Copy link

How should I use this tool if I have an application that shares the same database on all domains?

For example,

If i have this tables

Products
Settings
Menus

Would I need to add the domain as an id in each model and add a global scope to filter by domain?

@gecche
Copy link
Owner

gecche commented Jul 27, 2021

Hi,

yes this is a possible solution.

Other solutions could be

  • use distinct tables for each domain, setting them in the model class depending upon the domain.
  • use two separate dbs: one centralized db with the data shared across all the domains, and one specific db for each domain containing only the domain specific tables (this is a solution which I used in various settings when I have centralized and localized data but obviously building the queries is a bit more complicated)
    Cheers

Giacomo

@centralcybersecurity
Copy link

centralcybersecurity commented Jul 29, 2021

Okay, my approach is:

  1. Each domain, separate DB ==> details are fed into .env.domain.test file

  2. For domain-specific details
    a. I created a config file - home-blocks.php
    Nothing but a json array ==>
    'domain.test' =>
    'Blocks'
    'Benefit Blocks'
    'Featured Blocks'
    ..... (whatever data I want for that domain)

  3. Then fetch the domain using getDomain() function in helpers.php and pass it to the controllers and views using AppServiceProvider:

    view()->composer('*',function($view) {
    $view->with('domain', getDomain() );
    });

Now, in the view or controller file, I just call those values like this in my controller:

  public function index()
    {
         $domain=$this->domain;
         $benefit_blocks=Config::get('home-blocks.'.$domain.'.blocks.benefit_blocks');
          return view('home', compact( 'benefit_blocks' ));
  }

As for the menu, I am using https://github.com/nWidart/laravel-menus/
and I just call my menu name which is the same as my domain name ...

      {!! Menu::render( $domain ) !!}

Again, my laravel skills are pretty basic and I have no idea whether this is an efficient approach.

Hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants