35 lines
564 B
PHP
35 lines
564 B
PHP
<?php
|
|
|
|
/**
|
|
* Ensures we retrieve and save models with the correct site_id
|
|
*/
|
|
namespace App\Traits;
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use App\Models\Site;
|
|
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();
|
|
}
|
|
|
|
public function site()
|
|
{
|
|
return $this->belongsTo(Site::class);
|
|
}
|
|
} |