osb/app/Traits/SiteID.php

29 lines
472 B
PHP
Raw Normal View History

2021-12-17 05:09:03 +00:00
<?php
/**
* Ensures we retrieve and save models with the correct site_id
*/
namespace App\Traits;
use Illuminate\Support\Arr;
use App\Models\Scopes\SiteScope;
trait SiteID
{
/**
* This model is site scoped
*/
protected static function booted()
{
static::addGlobalScope(new SiteScope);
}
public function save(array $options = [])
{
if (! Arr::get($this->attributes,'site_id'))
$this->site_id = config('site')->site_id;
return parent::save();
}
}