PHPackages                             kz370/krayin-multi-tenancy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kz370/krayin-multi-tenancy

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kz370/krayin-multi-tenancy
==========================

A multi-tenancy package for Krayin CRM.

v1.0.0(4mo ago)1128MITBladePHP ^8.1

Since Dec 16Pushed 4mo agoCompare

[ Source](https://github.com/kz370/krayin-multi-tenancy)[ Packagist](https://packagist.org/packages/kz370/krayin-multi-tenancy)[ RSS](/packages/kz370-krayin-multi-tenancy/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Krayin CRM Multi-Tenancy
========================

[](#krayin-crm-multi-tenancy)

A multi-tenancy extension for Krayin CRM. This package enables **Database-per-Tenant** architecture, allowing you to host multiple isolated organizations on a single Krayin installation.

[![Tenants Overview](https://raw.githubusercontent.com/kz370/krayin-multi-tenancy/refs/heads/main/tenants.webp)](https://raw.githubusercontent.com/kz370/krayin-multi-tenancy/refs/heads/main/tenants.webp)

Installation
------------

[](#installation)

1. **Install via Composer:**

    ```
    composer require kz370/krayin-multi-tenancy
    ```
2. **Publish Config &amp; Migrations:**

    ```
    php artisan vendor:publish --tag=krayin-multi-tenancy-config
    php artisan vendor:publish --tag=krayin-multi-tenancy-migrations
    ```
3. **Environment Setup:**The package automatically uses your primary database connection (`DB_DATABASE`) as the "Landlord" (Central) database.

    Ensure your database user (in `.env`) has **CREATE DATABASE** permissions, as the package automatically creates new databases for each tenant.

    VariableDefaultDescription`DB_CONNECTION``mysql`The default connection.`DB_LANDLORD_DATABASE``NULL`Optional. Defaults to your main `DB_DATABASE`.
4. **Setup Landlord Database:**Run the migrations and the Krayin installer to set up the main system tables (including the `tenants` table).

    ```
    php artisan migrate
    php artisan krayin-crm:install
    ```

🔐 Database User Permissions (Required)
--------------------------------------

[](#-database-user-permissions-required)

This package automatically creates a **new database for each tenant**. Before using it, ensure that the database user configured in your `.env` file has permission to create databases.

### Minimum Requirement

[](#minimum-requirement)

Your database user **must** have the `CREATE DATABASE` privilege.

If this permission is missing, tenant creation will fail.

---

### Recommended (Safer) Permission Setup

[](#recommended-safer-permission-setup)

For better security, it is strongly recommended to use a **dedicated database user** that can only manage tenant databases matching a specific naming pattern.

For example, if your tenant databases use a prefix like:

```
krayin_

```

You can grant permissions **only** for those databases:

```
GRANT ALL PRIVILEGES ON `krayin_%`.* TO 'krayin_tenant_user'@'%';
FLUSH PRIVILEGES;
```

This ensures:

- The user **cannot access unrelated databases**
- Only tenant databases managed by this package are affected
- Reduced risk in case of credential exposure

---

### Using a Dedicated Tenant Database User (Optional)

[](#using-a-dedicated-tenant-database-user-optional)

You may optionally configure a separate database user exclusively for tenant management:

```
DB_USERNAME=krayin_tenant_user
DB_PASSWORD=strong_password_here
```

This user should **only** have privileges for tenant databases (using the prefix rule above), while your main application database can remain protected.

---

### Summary

[](#summary)

- ✅ `CREATE DATABASE` permission is **required**
- 🔒 Prefix-based permissions are **recommended**
- 🛡 Dedicated database users improve overall security

---

Configuration
-------------

[](#configuration)

You can customize behavior in `config/multi_tenancy.php`.

OptionKeyDefaultDescription**Menu Visibility**`show_menu``true`Show/Hide "Tenants" in the admin sidebar.**Database Prefix**`database_prefix``'krayin_'`Prefix for generated tenant DBs (e.g., `krayin_client1`).**Landlord Connection**`landlord_connection_name``'landlord'`Internal connection name for the central DB.Usage
-----

[](#usage)

### 1. Create a Tenant

[](#1-create-a-tenant)

1. Log in to the **Landlord Admin Panel** (your main domain, e.g., `app.com`).
2. Navigate to **Tenants** in the sidebar.
3. Click **Add Tenant** and enter:
    - **Name**: The internal name for the tenant (e.g., "Acme Corp").
    - **Subdomain**: The prefix for their URL (e.g., `acme` -&gt; `acme.app.com`).
    - **Admin Details**: The initial login credentials for the tenant's administrator.
4. **Hit Save.**
    - *System Action:* The package creates a new database `krayin_acme`, runs all migrations, and seeds the admin user.

### 2. Access a Tenant

[](#2-access-a-tenant)

1. Navigate to the tenant's subdomain (e.g., `http://acme.localhost` or `http://acme.app.com`).
2. Log in with the **Admin Email** and **Password** defined during creation.
3. All data created here (Leads, Persons, Settings) is essentially invisible to other tenants.

Important Notes
---------------

[](#important-notes)

- **Wildcard Subdomains:** For production, ensure your DNS is configured to handle wildcard subdomains (`*.yourdomain.com`) pointing to your server.
- **Local Development:** If testing locally, you must add subdomains to your `/etc/hosts` file (e.g., `127.0.0.1 client1.localhost`) or use a tool like Laravel Valet or Laragon that handles this automatically.
- **Database User:** The MySQL user configured in your `.env` must have privileges to create and drop databases.

Artisan Commands
----------------

[](#artisan-commands)

Use these commands to keep tenant databases up to date with your code.

CommandDescription`php artisan tenants:migrate`Run `migrate` on **all** active tenant databases.`php artisan tenants:migrate 5`Run `migrate` on a specific tenant (ID: 5).`php artisan tenants:migrate --fresh --seed`**Destructive**: Wipe and re-seed all tenant databases.Troubleshooting
---------------

[](#troubleshooting)

### 1. 404 Not Found on Tenant Subdomain

[](#1-404-not-found-on-tenant-subdomain)

- **Localhost:** Ensure you have added the subdomain to your hosts file.
    - Windows: `C:\Windows\System32\drivers\etc\hosts`
    - Mac/Linux: `/etc/hosts`
    - Entry: `127.0.0.1  client1.localhost`
- **Production:** Ensure you have a **Wildcard DNS** A-Record (`*.yourdomain.com`) in your domain registrar pointing to your server's IP address.

### 2. "Access Denied" during Tenant Creation

[](#2-access-denied-during-tenant-creation)

- The package tries to create a **new SQL database** automatically.
- Ensure the `DB_USERNAME` in your `.env` file has the `CREATE DATABASE` permission.
- *Fix:* Grant full privileges to your database user or ensure they can create new databases.

### 3. Migrations applied to Landlord but not Tenant

[](#3-migrations-applied-to-landlord-but-not-tenant)

- Running `php artisan migrate` **ONLY** updates the Landlord (Central) database.
- To update tenant databases (e.g., if you added a new column to `leads`), you must run: ```
    php artisan tenants:migrate
    ```

### 4. Admin Login Failed on Tenant

[](#4-admin-login-failed-on-tenant)

- Users are isolated. An admin account created on the Landlord (Main Domain) **does not exist** on the Tenant database.
- Use the specific credentials you defined in the "Admin Details" section when you created the Tenant.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance74

Regular maintenance activity

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

147d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a83ad798b7fe8683b4388105008c4cf18937268bf490bc8379528d362cfc5117?d=identicon)[khaledz370](/maintainers/khaledz370)

---

Top Contributors

[![kz370](https://avatars.githubusercontent.com/u/94254886?v=4)](https://github.com/kz370 "kz370 (1 commits)")

---

Tags

laravelcrmmulti-tenancykrayin

### Embed Badge

![Health badge](/badges/kz370-krayin-multi-tenancy/health.svg)

```
[![Health](https://phpackages.com/badges/kz370-krayin-multi-tenancy/health.svg)](https://phpackages.com/packages/kz370-krayin-multi-tenancy)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[zonneplan/laravel-module-loader

Module loader for Laravel

24118.4k](/packages/zonneplan-laravel-module-loader)[dragon-code/pretty-routes

Pretty Routes for Laravel

10058.7k4](/packages/dragon-code-pretty-routes)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)[glhd/special

1929.4k](/packages/glhd-special)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
