tenancy-docs/docs/source/v2/creating-tenants.blade.md
2019-09-30 18:51:26 +02:00

1.2 KiB

title description extends section
Creating Tenants Creating tenants _layouts.documentation content

Creating Tenants

Make sure your database is correctly [configured]({{ $page->link('configuration/#database') }}) before creating tenants.

To create a tenant, you can use

use Stancl\Tenancy\Tenant;

Tenant::new()
    ->withDomains(['tenant1.yourapp.com', 'tenant1.com'])
    ->withData(['plan' => 'free'])
    ->save();

Tip: All domains under .localhost are routed to 127.0.0.1 on most operating systems. This is useful for development.

The withDomains() and withData() methods are optional.

You can also create a tenant using a single method: Tenant::create:

$domains = ['tenant1.myapp.com', 'tenant1.com'];
Tenant::create($domains, [
    'plan' => 'free',
]);

Tenant::create() works with both Stancl\Tenancy\Tenant and the facade, \Tenant.

Note: By default, creating a tenant doesn't run [migrations]({{ $page->link('tenant-migrations' )}}) automatically. You may change this behavior using the migrate_after_creation [configuration]({{ $page->link('configuration#migrate-after-creation') }}).