protected static function boot() { parent::boot(); static::creating(function ($entity) { if (!Schema::hasCollection('entities')) { static::createSchema(); } if (empty($entity->project)) { throw new Exception("No project was given"); } if (!empty($entity->hash) && !empty($entity->project)) { if (Entity::withTrashed()->where('hash', $entity->hash)->where('project', $entity->project)->first()) { throw new Exception("Hash already exists for: " . $entity->title . " in project " . $entity->project); } } $entity->_id = static::generateIncrementedBaseURI($entity); if (Auth::check()) { $entity->user_id = Auth::user()->_id; } else { $entity->user_id = "crowdtruth"; } }); static::saved(function ($entity) { Temp::truncate(); Cache::flush(); }); static::deleted(function ($entity) { Cache::flush(); }); }
public static function boot() { parent::boot(); static::saving(function ($template) { if (!Schema::hasCollection('templates')) { static::createSchema(); } static::validateTemplate($template); }); }