本文整理汇总了PHP中Illuminate\Database\Eloquent\Collection::put方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::put方法的具体用法?PHP Collection::put怎么用?PHP Collection::put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Collection
的用法示例。
在下文中一共展示了Collection::put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: byLocale
/**
* @return Collection
*/
public function byLocale()
{
$collection = $this->groupBy('locale_id');
$response = new Collection();
$locales = app('Modules\\System\\Locale')->all();
foreach ($locales as $locale) {
$response->put($locale->slug, $collection->get($locale->id, new Collection()));
}
return $response;
}
示例2: getMeta
/**
* Gets meta data
*
* @param string $key
* @param null|mixed $default
* @param bool $raw
* @return Collection
*/
public function getMeta($key, $default = null, $raw = false)
{
$meta = $this->meta()->where('key', $key)->get();
if ($raw) {
$collection = $meta;
} else {
$collection = new Collection();
foreach ($meta as $m) {
$collection->put($m->id, $m->value);
}
}
if (0 == $collection->count()) {
return $default;
}
return $collection->count() <= 1 ? $collection->first() : $collection;
}
示例3: serializeRelations
/**
* Serialize intance's relations.
*
* @param \Illuminate\Support\Contracts\ArrayableInterface $instance
* @return array
*/
public function serializeRelations(ArrayableInterface $instance)
{
$result = new Collection();
if (!$this->isCollection($instance)) {
$collection = new Collection();
$instance = $collection->add($instance);
}
$sub_result = $this->collectRelations($instance);
$sub_result = $this->mergeRelations($sub_result);
foreach ($sub_result as $id => $value) {
$result->put($id, $value);
}
return $result->toArray();
}