Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This might not be an appropriate question for stackoverflow....as it might be too specific.

But I was wondering if anybody knows how I would have one installation of Laravel, serving a site. But depending on the url, I can access different databases.

Ie...

www.mainsite.com/company1/login - database1

www.mainsite.com/company1/users - database1

..

www.mainsite.com/company2/login - database2

www.mainsite.com/company2/users - database2

So in the cases above, the site being served is the exact same site. But of course, each part has a login, and accesses a different database.

I know I can do this by having multiple installations of laravel, and thats actually how Im doing it right now....

But I wanna be able to just update ONE version....instead of having to copy my changes to all the different folders.

Then just serve that one site to all the multiple different companies. With them having access to only their database

Is this possible??

share|improve this question

1 Answer 1

You could define multiple databases in your config:

'default' => 'database1',
'connections' => array(
    'database1' => array(
        'driver'   => 'mysql',
        'host'     => 'localhost',
        'database' => 'database1',
        'username' => 'root',
        'password' => '',
        'charset'  => 'utf8',
        'prefix'   => '',
    ),

    'database2' => array(
        'driver'   => 'mysql',
        'host'     => 'localhost',
        'database' => 'database2',
        'username' => 'root',
        'password' => '',
        'charset'  => 'utf8',
        'prefix'   => '',
    ),

), 

Then query using fluent:

$user = DB::connection('database2')->table('users')->where('id', '=', 1)->first();

Maybe you could use environments, something like this:

$environments = array(
  'company1' => array('http://server.com/company1*'),
  'company2' => array('http://server.com/company2*'),
);

Then create your subfolders in the config and copy of the db config to edit as needed.

share|improve this answer
    
Yeah I thought about doing that, but then can you do eloquent queries? Or are you stuck with raw and fluent then? Cuz I have multiple relationships that rely on eloquent pretty heavily –  KyleK Jul 12 '13 at 21:55
    
Maybe you can use environments, see my edited answer. –  Matthew Camp Jul 13 '13 at 15:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.