Eloquent Tenant Provider

You're working with Laravel, so you're most likely going to have be using Eloquent to define your tenant. In that case, you'll also need to make use of the Eloquent tenant provider.

Introduction

The eloquent tenant provider is a driver for Sprouts tenant provider functionality that allows you to use Eloquent as your tenant. It's a relatively simple tenant provider to configure and use.

Using

When configuring your provider in the multitenancy config you only need to do two things to use this tenant provider. Set the driver to eloquent and provide a model using the model config option. An example config entry for this tenant provider looks like so:

1'providers' => [
2 'tenants' => [
3 'driver' => 'eloquent',
4 'model' => MyModel::class,
5 ],
6]

When the eloquent tenant provider is created, the model class will be validated and must meet the following criteria.

  • It MUST exist at runtime.
  • It MUST implement the Sprout\Contracts\Tenant interface, either directly or indirectly.
  • It MUST be a descendant of the Illuminate\Database\Eloquent\Model class.

For more information about creating a tenant model, check out the tenant models config entry.