本文整理汇总了PHP中Illuminate\Support\Arr::pluck方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::pluck方法的具体用法?PHP Arr::pluck怎么用?PHP Arr::pluck使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Arr
的用法示例。
在下文中一共展示了Arr::pluck方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: explode
/**
* Get an item from an array or object using "dot" notation.
*
* @param mixed $target
* @param string|array $key
* @param mixed $default
* @return mixed
*/
function data_get($target, $key, $default = null)
{
if (is_null($key)) {
return $target;
}
$key = is_array($key) ? $key : explode('.', $key);
while (($segment = array_shift($key)) !== null) {
if ($segment === '*') {
if ($target instanceof Collection) {
$target = $target->all();
} elseif (!is_array($target)) {
return value($default);
}
$result = Arr::pluck($target, $key);
return in_array('*', $key) ? Arr::collapse($result) : $result;
}
if (Arr::accessible($target) && Arr::exists($target, $segment)) {
$target = $target[$segment];
} elseif (is_object($target) && isset($target->{$segment})) {
$target = $target->{$segment};
} else {
return value($default);
}
}
return $target;
}
示例2: testBulkOperationException
public function testBulkOperationException()
{
$bulkItems = new Collection([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4]]);
$items = [['create' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 1, 'status' => 409, 'error' => ['type' => 'document_already_exists_exception', 'reason' => '[my_index][1]: document already exists', 'shard' => '1', 'index' => 'my_index']]], ['update' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 2, 'status' => 404, 'error' => ['type' => 'document_missing_exception', 'reason' => '[my_index][2]: document missing', 'shard' => '-1', 'index' => 'my_index']]], ['delete' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 3, 'status' => 404, 'found' => false]], ['index' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 4, 'status' => 200]]];
$e = BulkOperationException::createForResults($items, $bulkItems->all());
$failedItems = $e->getFailedItems();
$failedIds = Arr::pluck($failedItems, 'id');
$this->assertEquals([1, 2], $failedIds);
}
示例3: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$ids = $this->argument('id');
if (count($ids) === 1 && $ids[0] === 'all') {
$ids = Arr::pluck($this->laravel['queue.failer']->all(), 'id');
}
foreach ($ids as $id) {
$this->retryJob($id);
}
}
示例4: pluck
/**
* Get the values of a given key.
*
* @param string $value
* @param string|null $key
* @return static
*/
public function pluck($value, $key = null)
{
return new static(Arr::pluck($this->items, $value, $key));
}
示例5: pluck
/**
* Get an array with the values of a given column.
*
* @param string $column
* @param string|null $key
* @return array
*/
public function pluck($column, $key = null)
{
$results = $this->get(is_null($key) ? [$column] : [$column, $key]);
// If the columns are qualified with a table or have an alias, we cannot use
// those directly in the "pluck" operations since the results from the DB
// are only keyed by the column itself. We'll strip the table out here.
return Arr::pluck($results, $this->stripTableForPluck($column), $this->stripTableForPluck($key));
}
示例6:
/**
* Pluck an array of values from an array.
*
* @param array $array
* @param string $value
* @param string $key
* @return array
*/
function array_pluck($array, $value, $key = null)
{
return Arr::pluck($array, $value, $key);
}
示例7: function
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Response;
use Zend\Feed\Exception\InvalidArgumentException;
use Zend\Feed\Writer\Entry;
use Zend\Feed\Writer\Feed;
Route::get('/feeds/{path}', function ($path) {
/** @type FeedModel $model */
$model = FeedModel::where('path', '=', $path)->first();
if ($model === null) {
return Response::make('Not Found', 404);
}
$feed = new Feed();
$feed->setTitle($model->getAttribute('title'))->setDescription($model->getAttribute('description'))->setBaseUrl(Url::to('/'))->setGenerator('OctoberCMS/Adrenth.RssFetcher')->setId('Adrenth.RssFecther.' . $model->getAttribute('id'))->setLink(Url::to('/feeds/' . $path))->setFeedLink(Url::to('/feeds/' . $path), $model->getAttribute('type'))->setDateModified()->addAuthor(['name' => 'OctoberCMS']);
/** @type Collection $sources */
$sources = $model->sources;
$ids = Arr::pluck($sources->toArray(), 'id');
$items = [];
Source::with(['items' => function ($builder) use(&$items, $model) {
$items = $builder->where('is_published', '=', 1)->whereDate('pub_date', '=', date('Y-m-d'))->orderBy('pub_date', 'desc')->limit($model->getAttribute('max_items'))->get();
}])->whereIn('id', $ids)->where('is_enabled', '=', 1)->get();
/** @type Item $item */
foreach ($items as $item) {
try {
$entry = new Entry();
$entry->setId((string) $item->getAttribute('id'))->setTitle($item->getAttribute('title'))->setDescription($item->getAttribute('description'))->setLink($item->getAttribute('link'))->setDateModified($item->getAttribute('pub_date'));
$comments = $item->getAttribute('comments');
if (!empty($comments)) {
$entry->setCommentLink($comments);
}
$category = $item->getAttribute('category');
if (!empty($category)) {
示例8: alreadyJoined
/**
* Determine whether given table has been already joined.
*
* @param \Sofa\Eloquence\Builder $query
* @param string $table
* @return boolean
*/
protected function alreadyJoined(Builder $query, $table)
{
$joined = Arr::pluck((array) $query->getQuery()->joins, 'table');
return in_array($table, $joined);
}
示例9: prepareChartData
/**
* Prepare chart data.
*
* @param \Arcanedev\LogViewer\Tables\StatsTable $stats
*
* @return string
*/
protected function prepareChartData(StatsTable $stats)
{
$totals = $stats->totals()->all();
return json_encode(['labels' => Arr::pluck($totals, 'label'), 'datasets' => [['data' => Arr::pluck($totals, 'value'), 'backgroundColor' => Arr::pluck($totals, 'color'), 'hoverBackgroundColor' => Arr::pluck($totals, 'highlight')]]]);
}
示例10: pluck
/**
* Get an array with the values of a given column.
*
* @param string $column
* @param string|null $key
* @return array
*/
public function pluck($column, $key = null)
{
$results = $this->get(is_null($key) ? [$column] : [$column, $key]);
// Convert ObjectID's to strings
if ($key == '_id') {
$results = $results->map(function ($item) {
$item['_id'] = (string) $item['_id'];
return $item;
});
}
$p = Arr::pluck($results, $column, $key);
return $this->useCollections ? new Collection($p) : $p;
}