Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

archboard/tidal-ptc

4 stars
3 code files
View archboard/tidal-ptc on GitHub

app/Models/Scopes/SchoolScope.php

Open in GitHub
use App\Models\School;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
 
class SchoolScope implements Scope
{
public function apply(Builder $builder, Model $model): void
{
if ($school = School::current()) {
$builder->where($model->getTable().'.school_id', $school->id);
}
}
}

app/Traits/ScopedToSchool.php

Open in GitHub
use App\Models\Scopes\SchoolScope;
 
trait ScopedToSchool
{
public static function bootScopedToSchool(): void
{
static::addGlobalScope(new SchoolScope());
}
}

app/Models/Batch.php

Open in GitHub
use App\Traits\ScopedToSchool;
 
class Batch extends Model
{
use ScopedToSchool;
 
// ...
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.