hipsterjazzbo / Landlord

A simple, single database multi-tenancy solution for Laravel 5.2+
MIT License
615 stars 138 forks source link

Unique validation not working with tenant_id #67

Closed xyrintech closed 7 years ago

xyrintech commented 7 years ago

Unique validation is not working with tenant_id

HelgeSverre commented 7 years ago

Please provide more context.

xyrintech commented 7 years ago

The tenant scope not getting applied. In a middleware I am applying tenant using addTenant method This is my table structure:

tenants id user_id

channels id tenant_id (reference from tenants table) name

In a controller to save Channel $this->validate($request, [ 'name' => 'required|unique:channels, name' ])

The tenant scope is not getting applied for this while checking the uniqueness of the data

HelgeSverre commented 7 years ago

Please copy and paste the code for the middleware and the channel model

HelgeSverre commented 7 years ago

Not sure if this is relevant, but i notice you have a space between "channels," and "name", might be related to the the problem if that causes the validator to think you want to check uniqueness for " name" column (that doesnt exist)... long short but worth a look.

xyrintech commented 7 years ago

Please ignore the typos in the code. Ideally in the channels table, name should be unique with tenant_id (i.e. composite keys)

Because multi tenants can have multiple channels. But this unique validation is not working as default if we use this package.