Add Compoships for multile key relationships, first implemented with Service::class

This commit is contained in:
Deon George
2022-09-29 17:26:03 +10:00
parent 2a19f14adb
commit ec99a5ff75
10 changed files with 99 additions and 43 deletions

View File

@@ -17,7 +17,12 @@ class SiteScope implements Scope
*/
public function apply(Builder $builder, Model $model)
{
// @todo Need to only do this, if the original query doesnt already have a where condition with a site_id
$builder->where($model->getTable().'.site_id',config('site')->site_id);
$builder->when(
! collect($builder->getQuery()->wheres)->pluck('column')->contains(function($item) { return preg_match('/^(.*[^.]\.)?site_id/',$item); }),
function($q) use ($model)
{
return $q->where($model->getTable().'.site_id',config('site')->site_id);
}
);
}
}