Add Compoships for multile key relationships, first implemented with Service::class
This commit is contained in:
@@ -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);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user