Site related updates

This commit is contained in:
Deon George
2021-12-17 16:09:03 +11:00
parent 8d194c5523
commit b7b6a575bc
10 changed files with 71 additions and 19 deletions

29
app/Traits/SiteID.php Normal file
View File

@@ -0,0 +1,29 @@
<?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();
}
}