public function testWithValidIdFilter() { $this->initDB(); $exitCode = Artisan::call('permission:show', ['permission' => $this->list->get(0)->id]); $this->assertEquals($exitCode, 0); $output = Artisan::output(); foreach (['Id', 'Name', 'Description'] as $el) { $this->assertContains($el, $output); } }
/** * @param array $setting * @return mixed * @throws Exception */ protected function settingGetType(array $setting) { if (!static::$types) { static::$types = ThemeSettingType::all()->keyBy('name'); } if (!static::$types->has($setting['type'])) { throw new Exception('Invalid setting type provided'); } return static::$types->get($setting['type']); }
public function testWithValidIdFilter() { $this->initDB(); $exitCode = Artisan::call('ticket:show', ['ticket' => $this->ticketList->get(1)->id]); $this->assertEquals($exitCode, 0); $output = Artisan::output(); $fields = ['Id', 'Ip', 'Domain', 'Class id', 'Type id', 'Last notify timestamp']; foreach ($fields as $el) { $this->assertContains($el, $output); } }
/** * Finally delete content item */ public function make() { // remove gallery files if exists foreach ($this->_records->get() as $record) { $galleryPath = '/upload/gallery/' . (int) $record->id; if (Directory::exist($galleryPath)) { Directory::remove($galleryPath); } } // finally remove from db $this->_records->forceDelete(); }
/** * Simulate a get clause on the collection. * * @param mixed $key * @param mixed $default * @return mixed */ public function get($key = null, $default = null) { if (is_null($key) and is_null($default)) { return $this; } return parent::get($key, $default); }
/** * Remove a meta key * * @param $key */ public function deleteMeta($key) { $this->loadMetaData(); /** @var Data $meta */ $meta = $this->metaData->get($key, null); if (!is_null($meta)) { $meta->deleteOnSave(); } }
/** * Get notFoundManyException. * @param $ids * @param Collection $models * @param string $keyName * @return ValidationExceptionCollection */ protected function notFoundManyException($ids, $models, $keyName = '') { $errors = []; $models->keyBy($keyName); foreach ($ids as $id) { if ($models->get($id)) { $errors[] = null; } else { $errors[] = $this->notFoundException($keyName); } } throw new ValidationExceptionCollection($errors); }
/** * Create a collection of models from a request collection * The method is more efficient if is passed a Collection of existing entries otherwise it will do a query for every entity. * @param array $requestCollection * @param EloquentCollection|null $existingModels * @return Collection */ public function hydrateRequestCollection(array $requestCollection, EloquentCollection $existingModels = null) { $keyName = $this->getKeyName(); $models = array_map(function ($item) use($keyName, $existingModels) { /** @var Model $model */ $model = null; $entityId = isset($item[$keyName]) ? $item[$keyName] : null; //if we have known models, get the model from the collection if ($existingModels) { $model = $existingModels->get($entityId); } //if the model couldn't be found, find it in the database directly, or create a new one if (!$model) { $model = $this->findOrNew($entityId); } $model->fill($item); return $model; }, $requestCollection); return $this->newCollection($models); }
public static function choose_from_collection(\Illuminate\Database\Eloquent\Collection $collection) { assert($collection->count(), 'Collection empty!'); return $collection->get($collection->keys()[mt_rand() % $collection->count()]); }
/** * 处理上方所有条件后, 执行查询语句, 返回结果集 * * @param array $columns 默认获取全部字段 * @return mixed */ protected function selectQuery(array $columns = []) : \Illuminate\Support\Collection { return $this->original->get($columns); }