Мне нужны отдельные базы данных для каждого развертывания (арендаторы). < /p> [code]public function store(Request $request) { Log::info("Starting deployment creation for slug: " . $request->slug);
// **Automatically Create and Configure Database** Log::info("Initializing tenancy for tenant: " . $tenant->id); tenancy()->initialize($tenant);
Log::info("Current Database After Initialization: " . DB::connection()->getDatabaseName());
// **Run Migrations for New Tenant** Log::info("Running migrations for tenant database: " . $tenant->database_name); Artisan::call('tenants:migrate', ['--tenants' => [$tenant->id]]); Log::info("Migrations completed for tenant: " . $tenant->database_name);
// **Create the Admin User for the New Tenant** Log::info("Creating admin user for tenant: " . $tenant->id); $tenant->run(function () use ($request) { Log::info("Inside tenant database: " . DB::connection()->getDatabaseName()); User::create([ 'name' => $request->tenant_name . ' Admin', 'email' => $request->contact_email, 'password' => Hash::make($request->password), 'role' => 1, // Admin role ]); Log::info("Admin user created successfully in tenant database."); });
// **Commit Transaction & Reset to Central DB** Log::info("Committing transaction and switching back to central database..."); DB::commit(); tenancy()->end(); Log::info("Deployment completed successfully for: " . $tenant->id);
return redirect()->route('deployments.index')->with('success', 'Deployment created successfully.'); } catch (Exception $e) { // **Rollback on Failure** DB::rollBack(); Log::error("Error during deployment creation: " . $e->getMessage());
tenancy()->end(); if ($tenant != null) { $tenant->delete(); // Remove failed deployment record Log::info("Rolled back deployment record for: " . $tenant->id); }