本文整理汇总了PHP中Illuminate\Support\Collection::each方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::each方法的具体用法?PHP Collection::each怎么用?PHP Collection::each使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::each方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInitial
public function getInitial()
{
$words = new Collection(explode(' ', $this->name));
// if name contains single word, use first N character
if ($words->count() === 1) {
if ($this->name->length() >= $this->length) {
return $this->name->substr(0, $this->length);
}
return (string) $words->first();
}
// otherwise, use initial char from each word
$initials = new Collection();
$words->each(function ($word) use($initials) {
$initials->push(Stringy::create($word)->substr(0, 1));
});
return $initials->slice(0, $this->length)->implode('');
}
示例2: __invoke
/**
* На самом деле тут у меня фантация играет по полной, поймать мошеника это круто
* можно было реализовать из hidden risk некую битовую маску и по ней уже обсчитывать мошеников
* @param Collection $leaders
* @param []Collection $prevLeaders
* @return []Collection
*/
public function __invoke(Collection $leaders, array $prevLeaders)
{
$leaders->each(function ($value) use($prevLeaders) {
$id = object_get($value, 'id', null);
$score = object_get($value, 'score', null);
// Идем по списку лидеров
foreach ($prevLeaders as $leaders) {
$leaders->each(function ($leader) use($id, $score) {
// Если личдер найден
if ($leader->id === $id) {
// И он есть в hidden risk
if (isset($this->hidRisk[$id])) {
// Удаляем его
unset($this->hidRisk[$id]);
}
// Если сейчас у него очков больше чем в прошлый раз
if ($leader->score < $score / static::RISK_GROWTH_SCOPE) {
$this->result[$id] = $leader;
} else {
$this->hidRisk[$id] = $leader;
}
}
});
}
if (isset($this->hidRisk[$id])) {
$this->result[$id] = $value;
}
});
return $this->result;
}
示例3: scrape
/**
* Start the site Scraping process.
*
* @return void
*/
public function scrape()
{
$scrape = new Scrape(new Client());
$this->list->each(function ($url) use($scrape) {
$this->writePage($url, $scrape->run($url));
});
}
示例4: setUp
/**
* Set up test environment.
*/
public function setUp()
{
parent::setUp();
$this->company = factory(Company::class)->create();
$this->users = factory(User::class, 5)->create(['company_id' => $this->company->id]);
$this->users->each(function ($user) {
factory(Task::class, 5)->create(['user_id' => $user->id]);
});
}
示例5: tearDown
public function tearDown()
{
$this->filesCreated->each(function ($file) {
try {
unlink($file);
} catch (Exception $e) {
}
});
parent::tearDown();
}
示例6: placeWidgetsToLayoutBlocks
/**
* @return void
*/
public function placeWidgetsToLayoutBlocks()
{
$this->sortWidgets();
$this->registeredWidgets->each(function (WidgetCollectionItem $widget) {
if (method_exists($widget->getObject(), 'onLoad')) {
app()->call([$widget->getObject(), 'onLoad']);
}
})->each(function (WidgetCollectionItem $widget) {
if (method_exists($widget->getObject(), 'afterLoad')) {
app()->call([$widget->getObject(), 'afterLoad']);
}
});
}
示例7: compileLess
/**
* @param \Illuminate\Support\Collection $files
* @return string
*/
public function compileLess($files)
{
$files->each(function ($value) {
$this->less->parseFile($value);
});
return $this->less->getCss();
}
示例8: cleanUp
protected function cleanUp(Collection $cleanableModels)
{
$cleanableModels->each(function (string $modelClass) {
$numberOfDeletedRecords = $modelClass::cleanUp($modelClass::query())->delete();
event(new ModelWasCleanedUp($modelClass, $numberOfDeletedRecords));
$this->info("Deleted {$numberOfDeletedRecords} record(s) from {$modelClass}.");
});
}
示例9: handle
/**
* Execute the job.
*
* @return Collection
*/
public function handle()
{
for ($i = 1; $i <= $this->amount; $i++) {
$this->codes->push($this->generateCode());
}
$this->checkDatabase();
/** @var \Illuminate\Database\Eloquent\Collection $products */
$products = collect();
/**
* Now it is safe to add to the DB
*/
$this->codes->each(function ($code) use($products) {
$products->push(new Code(compact('code')));
});
$this->product->codes()->saveMany($products);
return $products;
}
示例10: toArray
/**
* Get the array representation of attributes
* @return array Assoc array with attribute name in the key
* @since 1.0
*/
public function toArray()
{
$returnArr = [];
$this->attributes->each(function ($attribute) use(&$returnArr) {
/* @var ConfigurationAttribute $attribute **/
$returnArr[$attribute->getName()] = $attribute->getValue();
});
return $returnArr;
}
示例11: run
public function run()
{
$this->backupDestinations->each(function (BackupDestination $backupDestination) {
try {
if (!$backupDestination->isReachable()) {
throw new Exception("Could not connect to disk {$backupDestination->diskName()} because: {$backupDestination->connectionError()}");
}
consoleOutput()->info("Cleaning backups of {$backupDestination->backupName()} on disk {$backupDestination->diskName()}...");
$this->strategy->deleteOldBackups($backupDestination->backups());
event(new CleanupWasSuccessful($backupDestination));
$usedStorage = Format::humanReadableSize($backupDestination->usedStorage());
consoleOutput()->info("Used storage after cleanup: {$usedStorage}.");
} catch (Exception $exception) {
consoleOutput()->error("Cleanup failed because: {$exception->getMessage()}.");
event(new CleanupHasFailed($exception));
}
});
}
示例12: __invoke
/**
* @param Collection $leaders
* @param []Collection $prevLeaders Массив ранее собраных списков
* @return array
*/
public function __invoke(Collection $leaders, array $prevLeaders)
{
$leaders->each(function ($value) use($prevLeaders) {
$id = object_get($value, 'id', null);
$place = object_get($value, 'place', null);
$this->result[$id] = 0;
foreach ($prevLeaders as $leaders) {
$leaders->each(function ($value) use($id, $place) {
if ($value->id === $id) {
if ($value->place !== $place) {
$this->result[$id]++;
}
}
});
}
});
return $this->result;
}
示例13: saveChannels
public function saveChannels(Collection $data)
{
$data->each(function ($item, $key) {
$item->persist();
$game = $this->game->get($item->relatedGame);
if (!is_null($game)) {
$item->relatesToGame($game);
}
});
}
示例14: send
/**
* Send the notification to devices.
* Returns errors (APNs and GCM) and updated token (GCM).
*
* @return array [ 'errors': [ Device, ... ], 'updates' => [ [ 'device' => Device, 'token' => 'a-new-token' ], ... ] ]
*/
public function send()
{
$apns = new Collection();
$gcm = new Collection();
$this->devices->each(function (Device $device) use(&$apns, &$gcm) {
if ($device->isApns()) {
$apns->push($this->merge($device));
} elseif ($device->isGcm()) {
$gcm->push($this->merge($device));
}
});
$results = ['errors' => [], 'updates' => []];
$this->mergeResults($results, $this->pushApns($apns));
$this->mergeResults($results, $this->pushGcm($gcm));
// Reset
$apns = null;
$gcm = null;
$this->device = new Collection();
return $results;
}
示例15: removeBackupsForAllPeriodsExceptOne
protected function removeBackupsForAllPeriodsExceptOne(Collection $backupsPerPeriod)
{
$backupsPerPeriod->each(function (Collection $groupedBackupsByDateProperty, string $periodName) {
$groupedBackupsByDateProperty->each(function (Collection $group) {
$group->shift();
$group->each(function (Backup $backup) {
$backup->delete();
});
});
});
}