File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ name: run-tests
22
33on :
44 push :
5- branches : [master ]
5+ branches : [main ]
66 pull_request :
7- branches : [master ]
7+ branches : [main ]
88
99jobs :
1010 test :
Original file line number Diff line number Diff line change 88
99 'related_tenant_column ' => env ('TENANTABLE_RELATED_TENANT_COLUMN ' , 'tenant_id ' ),
1010
11+ /**
12+ * Allow the `tenant_id` to be null.
13+ *
14+ * If the entry does have null tenant_id, it will be considered as a global entry.
15+ */
16+ 'allow_nullable_tenant ' => env ('ALLOW_NULLABLE_TENANT ' , true ),
17+
1118 /**
1219 * The base model for tenant.
1320 */
Original file line number Diff line number Diff line change @@ -10,7 +10,17 @@ class TenantScope implements Scope
1010{
1111 public function apply (Builder $ builder , Model $ model )
1212 {
13- $ builder ->where ($ model ->qualifyColumn (config ('tenantable.related_tenant_column ' )), tenant ()->key ());
13+ $ column = $ model ->qualifyColumn (config ('tenantable.related_tenant_column ' ));
14+ $ tenantKey = tenant ()->key ();
15+
16+ if (config ('tenantable.allow_nullable_tenant ' )) {
17+ $ builder ->where (function (Builder $ query ) use ($ column , $ tenantKey ) {
18+ $ query ->whereNull ($ column )
19+ ->orWhere ($ column , $ tenantKey );
20+ });
21+ } else {
22+ $ builder ->where ($ column , $ tenantKey );
23+ }
1424 }
1525
1626 public function extend (Builder $ builder )
You can’t perform that action at this time.
0 commit comments