Support the ongoing development of Laravel.io →
posted 10 years ago
Database
Last updated 1 year ago.
0

I would setup multiple environments and databases and switch per domain.

That is the safest option but can be a little tricky.

Last updated 1 year ago.
0

you can setup your environments in bootstrap/start.php and then create a new database file per domain in app/config/<yourenv>/database.php

Last updated 1 year ago.
0

I was hoping to have all domains within one database and keep it as simple as possible.

I have the multiple domains working fine and I can load my views per domain without any issues, I guess my problem are my queries.

Last updated 1 year ago.
0

alexhackney said:

I was hoping to have all domains within one database and keep it as simple as possible.

I have the multiple domains working fine and I can load my views per domain without any issues, I guess my problem are my queries.

in that case you can make a Post Repository and use that throughout your app instead of your Post model

Last updated 1 year ago.
0

What do you mean by post repository?

Last updated 1 year ago.
0

I'm watching this now I'm assuming its what your talking about: https://laracasts.com/lessons/repositories-simplified

Last updated 1 year ago.
0

well normally you have something like

Post::find(1);

a repository is another class that looks like

class PostRepository {
    public static function find($id)
    {
        return Post::where('domain', '=', Session::get('domain'))->where('id', '=', $id)->first();
    }
}

so when you want to get the correct post for a specific domain you can do

PostRepository::find(1);

make sure you set the domain id in the Session

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2024 Laravel.io - All rights reserved.