Site related updates
This commit is contained in:
29
app/Traits/SiteID.php
Normal file
29
app/Traits/SiteID.php
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user