本文整理汇总了PHP中Illuminate\Database\Eloquent\Collection::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::get方法的具体用法?PHP Collection::get怎么用?PHP Collection::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Collection
的用法示例。
在下文中一共展示了Collection::get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testWithValidIdFilter
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);
}
}
示例2: settingGetType
/**
* @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']);
}
示例3: make
/**
* 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();
}
示例4: get
/**
* 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);
}
示例5: deleteMeta
/**
* 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();
}
}
示例6: notFoundManyException
/**
* 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);
}
示例7: hydrateRequestCollection
/**
* 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);
}
示例8: choose_from_collection
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()]);
}
示例9: selectQuery
/**
* 处理上方所有条件后, 执行查询语句, 返回结果集
*
* @param array $columns 默认获取全部字段
* @return mixed
*/
protected function selectQuery(array $columns = []) : \Illuminate\Support\Collection
{
return $this->original->get($columns);
}