add:新增 implode 方法

This commit is contained in:
JaguarJack 2021-02-27 18:30:40 +08:00
parent 50c8470d73
commit ddf521b62b
2 changed files with 22 additions and 9 deletions

View File

@ -19,7 +19,7 @@ class CatchModelCollection extends Collection
* @param string $children * @param string $children
* @return array * @return array
*/ */
public function toTree($pid = 0, $pidField = 'parent_id', $children = 'children') public function toTree($pid = 0, $pidField = 'parent_id', $children = 'children'): array
{ {
return Tree::done($this->items, $pid, $pidField, $children); return Tree::done($this->items, $pid, $pidField, $children);
} }
@ -35,7 +35,7 @@ class CatchModelCollection extends Collection
* @throws \PhpOffice\PhpSpreadsheet\Exception * @throws \PhpOffice\PhpSpreadsheet\Exception
* @return mixed|string[] * @return mixed|string[]
*/ */
public function export($header, $path = '', $disk = 'local') public function export($header, $path = '', $disk = 'local'): array
{ {
$excel = new Class($header, $this->items) implements ExcelContract $excel = new Class($header, $this->items) implements ExcelContract
{ {
@ -80,7 +80,7 @@ class CatchModelCollection extends Collection
* @return bool * @return bool
* @throws \Psr\SimpleCache\InvalidArgumentException * @throws \Psr\SimpleCache\InvalidArgumentException
*/ */
public function cache($key, int $ttl = 0, string $store = 'redis') public function cache($key, int $ttl = 0, string $store = 'redis'): bool
{ {
return Cache::store($store)->set($key, $this->items, $ttl); return Cache::store($store)->set($key, $this->items, $ttl);
} }
@ -94,18 +94,31 @@ class CatchModelCollection extends Collection
* @param string $column * @param string $column
* @return array * @return array
*/ */
public function getAllChildrenIds(array $ids, $parentFields = 'parent_id', $column = 'id') public function getAllChildrenIds(array $ids, $parentFields = 'parent_id', $column = 'id'): array
{ {
array_walk($ids, function (&$item){ array_walk($ids, function (&$item){
$item = intval($item); $item = intval($item);
}); });
$childDepartmentIds = $this->whereIn($parentFields, $ids)->column($column); $childIds = $this->whereIn($parentFields, $ids)->column($column);
if (!empty($childDepartmentIds)) { if (!empty($childIds)) {
$childDepartmentIds = array_merge($childDepartmentIds, $this->getAllChildrenIds($childDepartmentIds)); $childIds = array_merge($childIds, $this->getAllChildrenIds($childIds));
} }
return $childDepartmentIds; return $childIds;
}
/**
* implode
*
* @time 2021年02月24日
* @param string $separator
* @param string $column
* @return string
*/
public function implode(string $column = '', string $separator = ','): string
{
return implode($separator, $column ? array_column($this->items, $column) : $this->items);
} }
} }

View File

@ -116,7 +116,7 @@ class InstallProjectCommand extends Command
// 设置 app domain // 设置 app domain
$appDomain = strtolower($this->output->ask($this->input, '👉 first, you should set app domain: ')); $appDomain = strtolower($this->output->ask($this->input, '👉 first, you should set app domain: '));
if (strpos('http://', $appDomain) === false || strpos('https://', $appDomain) === false) { if (strpos($appDomain, 'http://') === false || strpos( $appDomain, 'https://') === false) {
$appDomain = 'http://' . $appDomain; $appDomain = 'http://' . $appDomain;
} }