本文整理汇总了PHP中Collection::pluck方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::pluck方法的具体用法?PHP Collection::pluck怎么用?PHP Collection::pluck使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection::pluck方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: combine
public static function combine($type, $files, $compress = false)
{
$root = panel::instance()->roots()->assets() . DS . $type;
$cache = new Media($root . DS . 'panel.' . $type);
$media = new Collection(array_map(function ($file) use($root) {
return new Media($root . DS . str_replace('/', DS, $file));
}, $files));
// get the max modification date
$modified = max($media->pluck('modified'));
if (is_writable($root) and (!$cache->exists() or $cache->modified() < $modified)) {
$cache->remove();
$content = '';
foreach ($media as $asset) {
$content .= $asset->read() . PHP_EOL;
}
if ($compress) {
$content = static::compress($content);
}
f::write($root . DS . 'panel.' . $type, $content);
}
if ($cache->exists()) {
return $type(panel()->urls()->{$type}() . '/panel.' . $type . '?v=' . panel()->version());
}
return $type(array_map(function ($item) use($type) {
return 'panel/assets/' . $type . '/' . $item;
}, $files));
}
示例2: postStore
public function postStore($id = null)
{
// ---------------------------------------- HANDLE REQUEST ----------------------------------------
// handle id
if (!is_null($id)) {
$data = $this->model->findorfail($id);
} else {
$data = $this->model->newInstance();
}
// ---------------------------------------- CHECK TAG ----------------------------------------
$tags_in_db = \App\Tag::whereIn('tag', Input::get('tags'))->get();
if (!$tags_in_db) {
$tags_in_db = new Collection();
}
foreach (Input::get('tags') as $x) {
if (!$tags_in_db->where('tag', $x)->first()->id) {
$new_tag = new \App\Tag(['tag' => $x]);
if (!$new_tag->save()) {
dd($new_tag->getErrors());
}
$tags_in_db->push($new_tag);
}
}
// ---------------------------------------- HANDLE SAVE ----------------------------------------
$input = Input::all();
if (!empty($input['published_at'])) {
$input['published_at'] = \Carbon\Carbon::createFromFormat('d/m/Y H:i', $input['published_at'])->format('Y-m-d H:i:s');
} else {
$input['published_at'] = null;
}
unset($input['longlat']);
$input['tag_ids'] = $tags_in_db->pluck('id')->toArray();
$data->fill($input);
if ($data->save()) {
if (!$this->save_required_images($data, $input)) {
return redirect()->back()->withInput()->withErrors($data->getErrors());
}
return redirect()->route('admin.' . $this->view_name . '.show', ['id' => $data->id])->with('alert_success', '"' . $data->{$data->getNameField()} . '" has been saved successfully');
} else {
return redirect()->back()->withInput()->withErrors($data->getErrors());
}
}
示例3: app_clean_admin_nav
/**
* Removed unused items from the admin nav
*/
function app_clean_admin_nav()
{
global $menu;
// Use regex to match b/c some items will have numbers suffixed (e.g. Comments 1)
$remove_titles = array('/Comments/i');
$items = array_combine(array_keys($menu), Collection::pluck($menu, 0));
foreach ($items as $id => $title) {
foreach ($remove_titles as $regex) {
if (!preg_match($regex, $title)) {
continue;
}
unset($menu[$id]);
break;
}
if (!array_key_exists($id, $menu)) {
continue;
}
}
}
示例4: zippy
/**
* Zippify the arrays. They must have the same number of elements.
* @param array @arrays
* @return array
*/
public static function zippy($arrays)
{
foreach ($arrays as $k => $array) {
$arrays[$k] = array_values($array);
}
$out = array();
$high_keys = array_keys($arrays);
$keys = array_keys(current($arrays));
foreach ($keys as $k) {
$out[] = array_combine($high_keys, Collection::pluck($arrays, $k));
}
return $out;
}