Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2017
    Posts
    12
    Rep Power
    0
    If your looking to get up and running quickly with a multi-tenant application you might want to check this out https://laravel-tenancy.com/
  2. #17
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,112
    Rep Power
    4103
    Originally Posted by bob8619
    I'm just too much of a visual learner so without seeing how a task is done I'm just useless.

    Here is some example code for how handled this in one application:
    Code:
        protected function lookupInstance(Request $request){
            $instance = null;
    
    
            $domain = $request->getHttpHost();
            if ($domain){
                /** @var InstanceRepository $repo */
                $repo = $this->em->getRepository('AppBundle:Instance');
                $instance = $repo->findByDomain($domain);
            }
    
    
            return $instance;
        }

    The code is based on Symfony so look that up if you want details on some of the objects.


    Basically the code does like requinix describes though. At the start of a request it grabs the HTTP_HOST value and tries to find the value in the database under my instance table. All the content in the database is tied to one of these instance records in some way or another. For example, when trying to find a user by their email addess (such as when logging in):


    Code:
        public function findExistingByEmail(Instance $instance, $email){
            $query = $this->createQueryBuilder('u');
            $query->select('u')
                ->innerJoin('u.instances', 'i')
                ->where('i = ?1')
                ->setParameter(1, $instance)
                ->andWhere('u.disabledOn is null')
                ->andWhere('u.email = ?2')
                ->setParameter(2, $email)
            ;
    
    
            $result = $query->getQuery()->execute();
            if ($result && count($result) == 1){
                return $result[0];
            }
    
    
            return null;
        }

    That creates and issues a query against the users table. As part of the WHERE condition it includes the instance id so that only users existing under the current domain are found.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Ft Myers FL
    Posts
    15
    Rep Power
    0
    I made one table named Table with 2 columns Domain and TestText. In the domain column I enter each domain that I have and then I put different text inside the testtext column. I stored the HTTP_HOST in a variable named $domain.

    Then I echo the following into an h1 tag: SELECT testtext FROM table WHERE domain ='$domain'. This works like a charm but is there any flaws with how I did it?
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo