This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
memberdb/app/Scopes/AddSiteId.php

30 lines
688 B
PHP
Raw Normal View History

<?php
namespace App\Scopes;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Config;
class AddSiteId implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function apply(Builder $builder, Model $model)
{
if (! in_array($model->table(),['account','setup']))
dd(__METHOD__,$model,$builder);
$so = Config::get('SITE_SETUP');
if (! $so instanceOf Setup OR ! $so->exists)
return;
$builder->where('site_id', '=', $so->id);
}
}