本文整理汇总了PHP中Illuminate\Database\Eloquent\Collection::pluck方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::pluck方法的具体用法?PHP Collection::pluck怎么用?PHP Collection::pluck使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Collection
的用法示例。
在下文中一共展示了Collection::pluck方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ofProjects
public static function ofProjects(\Illuminate\Database\Eloquent\Collection $projects)
{
return static::whereIn('project_id', $projects->pluck('id'))->orderBy('created_at', 'desc');
}
示例2: createMissingAbilities
/**
* Create abilities whose name is not in the given list.
*
* @param \Illuminate\Database\Eloquent\Collection $models
* @param array $abilities
* @param array $attributes
* @return \Illuminate\Database\Eloquent\Collection
*/
protected function createMissingAbilities(Collection $models, array $abilities, $attributes = [])
{
$missing = array_diff($abilities, $models->pluck('name')->all());
$created = [];
foreach ($missing as $ability) {
$created[] = Models::ability()->create($attributes + ['name' => $ability]);
}
return $created;
}
示例3: createMissingAbilities
/**
* Create abilities whose name is not in the given list.
*
* @param \Illuminate\Database\Eloquent\Collection $models
* @param array $abilities
* @return \Illuminate\Database\Eloquent\Collection
*/
protected function createMissingAbilities(Collection $models, array $abilities)
{
$missing = array_diff($abilities, $models->pluck('name')->all());
$created = [];
foreach ($missing as $ability) {
$created[] = Ability::create(['name' => $ability]);
}
return $created;
}
示例4: __construct
/**
* Create a new job instance.
*
* @param Collection $requests
* @param string $token Access token for Vk.com API
*/
public function __construct(Collection $requests, $token)
{
$this->requests = $requests;
$this->token = (string) $token;
VkRequest::whereIn('id', $requests->pluck('id')->all())->delete();
}
示例5: formatRoles
/**
* Get the user's role names.
*
* @return string
*/
public function formatRoles()
{
$this->loadRoles();
return $this->cachedRoles->pluck('name')->implode(', ');
}
示例6: lists
/**
* Get an array with the values of a given column.
*
* @param string $column
* @param string $key
* @return array
*/
public function lists($column, $key = null)
{
$columns = $this->getListSelect($column, $key);
// First we will just get all of the column values for the record result set
// then we can associate those values with the column if it was specified
// otherwise we can just give these values back without a specific key.
$res = $this->get($columns);
$results = new Collection($res->getData());
$values = $results->pluck($columns[0])->all();
// If a key was specified and we have results, we will go ahead and combine
// the values with the keys of all of the records so that the values can
// be accessed by the key of the rows instead of simply being numeric.
if (!is_null($key) && count($results) > 0) {
$keys = $results->pluck($key)->all();
return array_combine($keys, $values);
}
return $values;
}
示例7: appendCampaignToCollection
/**
* Append Campaign data to the supplied collection.
*
* @param \Illuminate\Database\Eloquent\Collection $collection
* @return \Illuminate\Database\Eloquent\Collection
*/
protected function appendCampaignToCollection($collection)
{
$campaignIds = $collection->pluck('campaign_id')->all();
$campaigns = $this->campaignRepository->getAll($campaignIds);
$campaigns = $campaigns->keyBy('id')->all();
foreach ($collection as $contest) {
if (isset($campaigns[$contest->campaign_id])) {
$contest->setAttribute('campaign', $campaigns[$contest->campaign_id]);
} else {
$contest->setAttribute('campaign', null);
}
}
return $collection;
}
示例8: createMissingPermissions
/**
* Create permissions whose name is not in the given list.
*
* @param \Illuminate\Database\Eloquent\Collection $models
* @param array $permissions
* @return \Illuminate\Database\Eloquent\Collection
*/
protected function createMissingPermissions(Collection $models, array $permissions)
{
$missing = array_diff($permissions, $models->pluck('name')->all());
$created = [];
foreach ($missing as $permission) {
$created[] = Models::permission()->create(['name' => $permission]);
}
return $created;
}