本文整理汇总了PHP中Illuminate\Support\Collection::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::filter方法的具体用法?PHP Collection::filter怎么用?PHP Collection::filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAttribute
/**
* Get an attribute by name
* @param string $name Attribute name
* @return ConfigurationAttribute|null
* @since 1.0
*/
public function getAttribute($name, $returnValue = true)
{
$attribute = $this->attributes->filter(function ($attr) use($name) {
/** @var ConfigurationAttribute $attr */
return $attr->getName() == $name;
})->first();
return $returnValue && $attribute ? $attribute->getValue() : $attribute;
}
示例2: filterColumns
protected function filterColumns($filters)
{
foreach ($filters as $key => $filter) {
$this->collection = $this->collection->filter(function ($row) use($key, $filter) {
return strpos(Str::lower($row[$key]), Str::lower($filter)) !== false;
});
}
}
示例3: reportFilter
/**
* @param Account $account
* @param Collection $startSet
* @param Collection $endSet
* @param Collection $backupSet
*
* @return Account
*/
public static function reportFilter(Account $account, Collection $startSet, Collection $endSet, Collection $backupSet)
{
// The balance for today always incorporates transactions made on today. So to get todays "start" balance, we sub one day.
$account->startBalance = '0';
$account->endBalance = '0';
$currentStart = $startSet->filter(function (Account $entry) use($account) {
return $account->id == $entry->id;
});
$currentBackup = $backupSet->filter(function (Account $entry) use($account) {
return $account->id == $entry->id;
});
// first try to set from backup
if (!is_null($currentBackup->first())) {
$account->startBalance = $currentBackup->first()->balance;
}
// overrule with data from start
if (!is_null($currentStart->first())) {
$account->startBalance = $currentStart->first()->balance;
}
$currentEnd = $endSet->filter(function (Account $entry) use($account) {
return $account->id == $entry->id;
});
if (!is_null($currentEnd->first())) {
$account->endBalance = $currentEnd->first()->balance;
}
return $account;
}
示例4: columnSearch
/**
* Perform column search.
*
* @return void
*/
public function columnSearch()
{
$columns = $this->request->get('columns');
for ($i = 0, $c = count($columns); $i < $c; $i++) {
if ($this->request->isColumnSearchable($i)) {
$this->isFilterApplied = true;
$regex = $this->request->isRegex($i);
$column = $this->getColumnName($i);
$keyword = $this->request->columnKeyword($i);
$this->collection = $this->collection->filter(function ($row) use($column, $keyword, $regex) {
$data = $this->serialize($row);
$value = Arr::get($data, $column);
if ($this->isCaseInsensitive()) {
if ($regex) {
return preg_match('/' . $keyword . '/i', $value) == 1;
} else {
return strpos(Str::lower($value), Str::lower($keyword)) !== false;
}
} else {
if ($regex) {
return preg_match('/' . $keyword . '/', $value) == 1;
} else {
return strpos($value, $keyword) !== false;
}
}
});
}
}
}
示例5: getGroup
/**
* @param $name
* @return Collection
*/
public function getGroup($name)
{
$group = $this->collection->filter(function ($widget) use($name) {
return $widget->group == $name;
});
return $group->sortBy('order');
}
示例6: generateMenu
/**
* @return Collection
*/
public function generateMenu()
{
$menu = new Collection();
if (!$this->auth->getUser()) {
return $menu;
}
if (config('shapeshifter.menu')) {
foreach (config('shapeshifter.menu') as $item) {
$item = $this->parseItem($item);
$menu->push($item);
}
} else {
foreach ($this->modules->getOrdered() as $module) {
$attributes = $module->json()->getAttributes();
$item = $this->parseItem($attributes);
$menu->push($item);
}
}
return $menu->filter(function ($item) {
return $this->hasAccessToRoute($item['route']);
})->map(function ($item) {
$item['children'] = array_filter($item['children'], function ($item) {
return $this->hasAccessToRoute($item['route']);
});
return $item;
})->filter(function ($item) {
return $this->hasAccessToRoute('superuser') || count($item['children']) === 0 && $item['route'] !== null;
});
}
示例7: applyFilterToMediaCollection
/**
* Apply given filters on media.
*
* @param \Illuminate\Support\Collection $media
* @param array|callable $filter
*
* @return Collection
*/
protected function applyFilterToMediaCollection(Collection $media, $filter) : Collection
{
if (is_array($filter)) {
$filter = $this->getDefaultFilterFunction($filter);
}
return $media->filter($filter);
}
示例8: cleanCollection
/**
* Delete all elements which are all keys is null
*
* @return void
*/
private function cleanCollection()
{
$this->collection = $this->collection->filter(function (Element $item) {
if (!$item->allKeyNull()) {
return true;
}
});
}
示例9: getTypeByClassName
/**
* @param string $needleClass
*
* @return string|null
*/
public function getTypeByClassName($needleClass)
{
$type = $this->types->filter(function (\KodiCMS\Widgets\Contracts\WidgetType $type) use($needleClass) {
return $type->getClass() == $needleClass or $this->isCorrupt($type->getClass());
})->first();
if ($type) {
return $type->getType();
}
}
示例10: getNotUndoRunningCommandCollection
/**
* Return a Collection of all Commands that have not running the undo action
* @return static
*/
protected function getNotUndoRunningCommandCollection()
{
return $this->commands->filter(function ($item) {
$value = $item->isUndoRun();
if ($value === false) {
return $item;
}
});
}
示例11: index
/**
* Show the application welcome screen to the user.
*
* @return mixed
*/
public function index()
{
$name = app('orchestra.app')->installed() ? 'welcome' : 'hello';
$packages = new Collection(config('website.packages', []));
$components = $packages->filter(function ($package) {
return in_array('component', $package['type']);
});
return view($name, compact('packages', 'components'));
}
示例12: updateFieldProperty
/**
* Activate a boolean property for the given fields.
* @param $property string fillable|guarded|in_table, etc
* @param $arguments array|string - * if all fields
* @return $this
*/
protected function updateFieldProperty($property, $arguments)
{
$fields = $arguments == "*" ? $this->fields : $this->fields->filter(function (FieldBlueprint $field) use($arguments) {
return in_array($field->getName(), $arguments);
});
$fields->each(function (FieldBlueprint $field) use($property) {
$field->setProperty($property, true);
});
return $this;
}
示例13: directoriesUsedByBackupJob
protected function directoriesUsedByBackupJob() : array
{
return $this->backupDestinations->filter(function (BackupDestination $backupDestination) {
return $backupDestination->filesystemType() === 'local';
})->map(function (BackupDestination $backupDestination) {
return $backupDestination->disk()->getDriver()->getAdapter()->applyPathPrefix('');
})->each(function (string $localDiskRootDirectory) {
$this->fileSelection->excludeFilesFrom($localDiskRootDirectory);
})->push($this->temporaryDirectory->path())->toArray();
}
示例14: getPrefixes
/**
* Search for any prefixes attached to this route.
*
* @return string
*/
protected function getPrefixes()
{
$router = app(\Illuminate\Routing\Router::class);
$this->prefixes = collect(explode('/', $router->getCurrentRoute()->getPrefix()));
// Remove the last prefix if it matches the controller.
$this->prefixes = $this->removeControllerFromPrefixes($this->prefixes);
if ($this->prefixes->count() > 0) {
$this->prefix = $this->prefixes->filter()->implode('.');
}
}
示例15: doInternalSearch
private function doInternalSearch(Collection $columns, array $searchColumns)
{
if (is_null($this->search) or empty($this->search)) {
return;
}
$value = $this->search;
$caseSensitive = $this->options['caseSensitive'];
$toSearch = array();
// Map the searchColumns to the real columns
$ii = 0;
foreach ($columns as $i => $col) {
if (in_array($columns->get($i)->getName(), $searchColumns)) {
$toSearch[] = $ii;
}
$ii++;
}
$self = $this;
$this->workingCollection = $this->workingCollection->filter(function ($row) use($value, $toSearch, $caseSensitive, $self) {
for ($i = 0; $i < count($row); $i++) {
if (!in_array($i, $toSearch)) {
continue;
}
$column = $i;
if ($self->getAliasMapping()) {
$column = $self->getNameByIndex($i);
}
if ($self->getOption('stripSearch')) {
$search = strip_tags($row[$column]);
} else {
$search = $row[$column];
}
if ($caseSensitive) {
if ($self->exactWordSearch) {
if ($value === $search) {
return true;
}
} else {
if (str_contains($search, $value)) {
return true;
}
}
} else {
if ($self->getExactWordSearch()) {
if (strtolower($value) === strtolower($search)) {
return true;
}
} else {
if (str_contains(strtolower($search), strtolower($value))) {
return true;
}
}
}
}
});
}