-
Notifications
You must be signed in to change notification settings - Fork 589
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
multi-site #50
Comments
Let me know if this is the right path: Ill try it out in the meantime and let you know... |
Hi @AlexECP. If you're using Laravel you does not have to call |
Done! ;-) Commit: 5b5798f |
@AlexECP just an advice. The change was made in |
awesome. For my specific use case I need to connect even though Im on Laravel, since the wordpress DB is external. |
Welcome @AlexECP. If you're using Corcel with Laravel you can create a new connection on Laravel config files and set it to your Wordpress models, like |
ah I see, then I would just do something like $post->getConnection()->setTablePrefix(...) ? Right? |
Yes and no @AlexECP hehe. It's better to you set the table prefix in the connection configuration array (config folder) so every model you have |
right, but for my case where its a multi-site, I will need to be changing the prefix all the time for example to publish a new post to 200 sites... before each save I will need to alter the prefix, I think |
Hummm ok ;-) Maybe in the future we can think in a generic solution to this using Corcel :-) |
Can't seem to find any documentation concerning corcel/corcel communicating with a multisite Wordpress installation - has nothing been written yet for this? Currently I have for example |
I've settled with this solution, which seems to work for now:
Then I just set multiple connections inside of
Not sure if this method is just sluggish or going to cause multiple connections / other issues? Would be keen to hear from someone else attempting this. |
I think having to setup multiple connection inside of
I also sometimes create static functions that take the wordpress site id as a parameter, and start with:
|
Hy @AharonFeinstein thanks for the contribution. I guess maybe it's better to create a
Actually there's no official support for multisite into Corcel but of course, that would be an excellent contribution! Be welcome! |
Hi @jgrossi, thanks for writing Corcel! It's perfect for the project we're about to work on, except that we definitely need multi-site functionality. I will use some of the suggestions above to start with, but I'd also be keen to put some work into extending Corcel to do it natively. But before I do, I'd love to know your thoughts on how best to do this. |
Hi @bluehaoran thanks for the kind words. About multi-site, Corcel works as a library, a composer package. There's no way to work with multiple websites using just a single database connection, but you can have as many database connections you want to, changing the prefix for each one. So using something like Would this help? |
@jgrossi thanks for taking the time to reply. As I see it, there are two problems to solve with multi-site:
I'm thinking that in this circumstance, you'd tweak the logic around generating the $table property of
Is that sensible? |
@bluehaoran actually you can access both database connections in the same request. The $posts = Post::on('site_1')->all(); // posts from `wp_posts`
$posts = Post::on('site_2')->all(); // posts from `wp_2_posts` Just to let things clear, the |
If you're on this thread, here's a little bug I picked up with Connections in Laravel (laravel/framework#26589). This mainly became an issue for me writing unit tests, but YMMV. |
@bluehaoran actually, about the laravel/framework#26589 that's the expected behavior. can you explain better which test you wrote? |
Hi,
Thanks for a great project!
If I am connecting to a multi-site wordpress, is there a way for me to change the prefix without needing to run \Corcel\Database::connect($params); again with the new prefix specified? This is for a project where I am connecting to our wordpress and posting articles to hundreds of sites.
The text was updated successfully, but these errors were encountered: