This is a Vemto plugin. Vemto is a GUI Laravel generator with a complete set of tools for starting new Laravel projects.
This plugin is intended to bring simple User Login multi-tenancy to your Vemto Laravel projects.
It adds a Trait (BelongsToTenant.php) to all models you marked as "owned by tenant", making it possible to create and list records that are owned by the Authenticated User.
By default, Vemto generates permissions and adds them to the super-admin (you need to change the code or manually add them to other users).
So, when using this plugin, it is recommended to initially disable the permissions modules, so it would not be necessary to manually add permissions or change the code to test the multi-tenancy.
This plugin has only two simple settings:
- Tenant field name: the field that is used to identify the tenant (the authentication model, that is User by default)
- Models owned by tenant - the models owned by the tenant - it is recommended to mark only models directly related to the "User" model (models that have a belongsTo:user relationship).
After marking a model as "owned by tenant", it will show a small yellow marker on the Schema Editor:
IMPORTANT: - all models marked as "owned by tenant" need to have a belongsTo:user relationship (or whatever authentication model you are using) and the relationship FK field needs to have the same name you configured on the Plugin Settings.
After generating the code, this plugin will add the trait BelongsToTenant.php to the models marked as "owned by tenant".
All models with that trait have a Global Scope that automatically saves the user_id (or the field you configured) and retrieves the data based on the Authenticated User.
If you want to retrieve something without the Tenancy Scope, you can use the withoutTenancy method. For example:
Order::all(); // Return all orders owned by the authenticated user
Order::withoutTenancy()->all(); // Return all orders from the database