/** @inheritdoc */ public function validate(array $data = [], $throwException = true) { if (empty($data)) { $data = $this->attributes; } if (parent::validate($data)) { $userId = ArrayUtils::get($data, 'user_id'); $appId = ArrayUtils::get($data, 'app_id'); if ($userId && $appId) { $model = $this->whereAppId($appId)->whereUserId($userId)->first(); if (!empty($model) && $model->id !== ArrayUtils::get($data, 'id')) { throw new BadRequestException('Multiple user-to-app-to-role assignment. You can only have a single user-to-app-to-role assignment.'); } } return true; } return false; }
/** * Run the database seeds. * * @throws \Exception */ public function run() { BaseModel::unguard(); if (empty($this->modelClass)) { throw new \Exception("Invalid seeder model. No value for {$this->modelClass}."); } /** @var BaseModel $modelName */ $modelName = $this->modelClass; $created = []; $updated = []; $extras = $this->getRecordExtras(); foreach ($this->records as $record) { $record = array_merge($record, $extras); /** @type \Illuminate\Database\Eloquent\Builder $builder */ $builder = null; $name = ''; if (!is_array($this->recordIdentifier)) { $name = ArrayUtils::get($record, $this->recordIdentifier); if (empty($name)) { throw new \Exception("Invalid seeder record. No value for {$this->recordIdentifier}."); } $builder = $modelName::where($this->recordIdentifier, $name); } else { foreach ($this->recordIdentifier as $identifier) { $id = ArrayUtils::get($record, $identifier); if (empty($id)) { throw new \Exception("Invalid seeder record. No value for {$identifier}."); } $builder = !$builder ? $modelName::where($identifier, $id) : $builder->where($identifier, $id); $name .= empty($name) ? $id : ':' . $id; } } if (!$builder->exists()) { // seed the record $modelName::create($record); $created[] = $name; } elseif ($this->allowUpdate) { // update an existing record $builder->first()->update($record); $updated[] = $name; } } $this->outputMessage($created, $updated); }
public function validate(array $data = [], $throwException = true) { if (empty($data)) { $data = $this->attributes; } if (!empty($disable = config('df.scripting.disable'))) { switch (strtolower($disable)) { case 'all': throw new ServiceUnavailableException("All scripting is disabled for this instance."); break; default: $type = isset($data['type']) ? $data['type'] : null; if (!empty($type) && false !== stripos($disable, $type)) { throw new ServiceUnavailableException("Scripting with {$type} is disabled for this instance."); } break; } } return parent::validate($data, $throwException); }
/** * {@inheritdoc} */ public static function selectByRequest(array $criteria = [], array $related = []) { $criteria = static::cleanCriteria($criteria); $response = parent::selectByRequest($criteria, $related); return static::cleanResult($response, ArrayUtils::get($criteria, 'select')); }