Answer the question
In order to leave comments, you need to log in
How to implement a marketplace on laravel?
It is necessary to make a kind of marketplace on laravel with mini sites for each store
As I see it
2 platforms on laravel
1- The main site where all information is uploaded from mini sites
2- Platform for mini sites
For each mini site, use its own database, or rather its own prefix in the database
(Each site has its own categories, dynamic pages, products, settings, roughly speaking 4 tables (so far) in the database for each mini site) and its own .env file
It turns out that you need to implement a connection to different databases for one project
How it works now:
In the file `/bootstrap/app.php`
Added code
if (isset($_SERVER['HTTP_HOST'])) {
$host = idn_to_utf8($_SERVER['HTTP_HOST'], 0, INTL_IDNA_VARIANT_UTS46);
$envFile = sprintf('site/%s', $host);
if ($host && file_exists(sprintf('%s/%s', $app['path.base'], $envFile))) {
$app->loadEnvironmentFrom($envFile);
}
}
try {
DB::connection()->getPdo();
if(DB::connection()->getDatabaseName()){
}
} catch (\Exception $e) {
abort(404);
}
$domain = $_SERVER['HTTP_HOST'] ?? '';
$site = Cache::remember('setting_domain_'.$domain, 1440, function () {
$site = \App\Setting::get()->keyBy('name')->toArray();
return $site;
});
config(['siteName' => $site['site_name']['value']]);
{{Config::get('siteName')}}
Answer the question
In order to leave comments, you need to log in
Yes, it will be fine. Do you have horizontal scaling?
Donor sites may be distributed across multiple cluster nodes.
The solution is very stupid and wrong.
It would be correct to use one database with a normal structure. Tie everything you need (these are your "categories, dynamic pages, products, settings") to the "mini-site" entity and that's it.
One base, one backend. No additional bases. Exchange with donors via api or parsing.
Multi-tenancy .
Now you are only thinking about connecting another base. But what about the queues? File systems?
1) leave .env for server settings
2) leave configs for configs, not for data storage
3) Remove logic from routes forever!
4) there is a powerful package https://github.com/tenancy/tenancy/tree/master
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question