Tenancy Options

Tenancy options are a way of modifying the configuration of Sprout per tenancy.

Introduction

Tenancy options are an additional layer of customisation that lets you control a few different things per configured tenancy. They're provided in the options config section when configuring a tenancy.

How they work

The options themselves are arbitrary string values that are essentially used as flags by any code that can make use of them. Each option has a pair of methods on the Sprout\TenancyOptions class, one that returns the value, and one that will check if a tenancy has that option.

There are currently only two tenancy options.

Hydrating Tenant Relations

This option, whose string value is tenant-relation.hydrate controls whether when loading a tenant-owned model from the database, the relation to that model that relates to the tenant should be automatically hydrated with the current tenant. You can add the option to a tenancy using TenancyOptions::hydrateTenantRelation().

1'options' => [
2 TenancyOptions::hydrateTenantRelation(),
3]

To check if a tenancy has the option, you can either use the hasOption() method on the Tenancy class, or use the helper method on TenancyOptions.

1if (TenancyOptions::shouldHydrateTenantRelation($tenancy)) {
2 
3}
4 
5if ($tenancy->hasOption(TenancyOptions::hydrateTenantRelation())) {
6 
7}

This options, whose string value is tenant-relation.strict controls how strict the handling of tenant child models is when it comes to the tenant relation. If this option is present within a tenancy, a tenant mismatch exception will be thrown if you attempt to create or retrieve a tenant child model who does not belong to the current tenant. You can add the option to a tenancy using TenancyOptions::throwIfNotRelated().

1'options' => [
2 TenancyOptions::throwIfNotRelated(),
3]

To check if a tenancy has the option, you can either use the hasOption() method on the Tenancy class, or use the helper method on TenancyOptions.

1if (TenancyOptions::shouldThrowIfNotRelated($tenancy)) {
2 
3}
4 
5if ($tenancy->hasOption(TenancyOptions::throwIfNotRelated())) {
6 
7}