本文整理汇总了PHP中array_pluck函数的典型用法代码示例。如果您正苦于以下问题:PHP array_pluck函数的具体用法?PHP array_pluck怎么用?PHP array_pluck使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_pluck函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: themeLists
public static function themeLists($target = null)
{
if ($target) {
$items = static::where('target', '=', $target)->get();
return array_pluck($items, 'name', 'id');
}
}
示例2: bindSelections
/**
* Validate and attach selection models via deferred bindings
*
* @param array $selections
* @return void
* @throws \October\Rain\Exception\ValidationException
*/
public function bindSelections($selections)
{
$collection = new Collection();
if (is_array($selections)) {
// Translate our selections into a collection
foreach ($selections['id'] as $i => $id) {
$selection = $id ? Selection::findOrNew($id) : new Selection();
$selection->sort_order = $i;
$selection->name = trim($selections['name'][$i]);
$selection->validate();
$collection->push($selection);
}
// Ensure selections are unique
$names = array_map('strtolower', array_pluck($collection->toArray(), 'name'));
if (count($names) > count(array_unique($names))) {
$message = Lang::get('bedard.shop::lang.selection.validation_unique');
Flash::error($message);
throw new ValidationException($message);
}
}
// Require at least one selection
if ($collection->count() === 0) {
$message = Lang::get('bedard.shop::lang.option.selection_required');
Flash::error($message);
throw new ValidationException($message);
}
// Bind the collection to the option
$this->bindEvent('model.afterSave', function () use($collection) {
$this->saveSelections($collection);
});
}
示例3: uniqueModuleList
/**
* 获取未分配的模块列表
* @param array $allModuleList
* @return array
*/
protected function uniqueModuleList(array $allModuleList)
{
$dbModuleList = AclModuleModel::all();
//获取数据库中所有模块信息
$dbModuleList = array_pluck($dbModuleList ? $dbModuleList->toArray() : [], 'ident');
return array_diff($allModuleList, $dbModuleList);
}
示例4: quiz
public function quiz()
{
if (Session::has('id') && (Session::get('type') === 'Student' || Session::get('type') === 'SuperAdmin')) {
//$questions = Question::all();
//$ansAr = array(
//);
$random_question = Question::orderBY(DB::raw('Rand()', 'Unique()'))->take(2)->get(array('id', 'q_description', 'q_opt_1', 'q_opt_2', 'q_opt_3', 'q_opt_4', 'q_ans'));
//print_r($random_question);
$cnt = 0;
foreach ($random_question as $tmp) {
// print_r($tmp);
// print("---------------\n-----------------");
$cnt++;
}
$totNoOfQus = $cnt;
//echo $cnt;
$correct_answer = array_pluck($random_question, 'q_ans');
$qIds = array_pluck($random_question, 'id');
$combined = array_combine($qIds, $correct_answer);
// echo '<pre>';
// print_r($combined);
// die;
Session::put('correct_answer', $combined);
Session::put('total_qus', $totNoOfQus);
// return $correct_answer;
return view::make('quiz')->with('title', 'QUIZ')->with('quiz', $random_question);
} else {
echo 'You are not authorised';
}
}
示例5: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (in_array('Admin', array_pluck(auth()->user()->roles->toArray(), 'name'))) {
return $next($request);
}
return redirect('/home');
}
示例6: __construct
/**
* TwoSelectBox constructor.
*
* @param $name
* @param $type
* @param Form $parent
* @param array $options
*/
public function __construct($name, $type, Form $parent, array $options)
{
$options['attr']['extend'] = true;
$options['attr']['multiple'] = true;
$options['btnSelect'] = array_merge(['class' => 'btn', 'id' => 'btnSelect'], isset($options['btnSelect']) ? $options['btnSelect'] : []);
$options['btnUnSelect'] = array_merge(['class' => 'btn', 'id' => 'btnUnSelect'], isset($options['btnUnSelect']) ? $options['btnUnSelect'] : []);
$options['container_id'] = Str::studly(Str::slug($name, '_')) . "TwoSelectBoxContainer";
/** Load data from model */
/** @var Model $model */
$model = $options['model'];
$primary = $options['primary'];
$show = $options['show'];
/** Detect I18N */
$locale = \Config::get('app.locale');
$is_i18n = method_exists($model, 'saveI18N');
$query = $is_i18n ? $model::I18N($locale) : $model::query();
/** END **/
if (key_exists('filter', $options) && count($options['filter']) > 0) {
foreach ($options['filter'] as $key => $item) {
$query->where($key, $item['condition'], $item['value']);
}
}
/** Parse to key-name format {$table}.{$field} */
$keyName = strpos($options['primary'], '.') ? $options['primary'] : (new $model())->getTable() . "." . $options['primary'];
$data = $query->select($keyName, $show)->get()->toArray();
/** Fill model data to choice array */
$options['choices'] = array_pluck($data, $show, $primary);
/** END */
$options['selected'] = array_get($options, 'value', []);
/** END */
$options['selected'] = (array) (isset($options['selected']) ? $options['selected'] : []);
parent::__construct($name, $type, $parent, $options);
}
示例7: handle
/**
* Handle the event.
*
* @param ProjectWatcher $event []
* @return void
*/
public function handle(ProjectWatcher $event)
{
$urlsFromDatabase = $event->project->urls->pluck('url');
if (is_string($urlsFromDatabase)) {
$urlsFromDatabase = (array) $urlsFromDatabase;
} else {
$urlsFromDatabase = $urlsFromDatabase->toArray();
}
$this->crawler->setBaseUrl($event->project->main_url);
$this->crawler->start();
$urlsFromWeb = array_merge($this->crawler->getSiteUrl(), $this->crawler->getSiteCss(), $this->crawler->getSiteJs());
if (empty($urlsFromDatabase)) {
foreach ($urlsFromWeb as $url) {
$this->addNewUrl($event, $url);
}
} else {
foreach ($urlsFromWeb as $url) {
if (!in_array($url['url'], $urlsFromDatabase)) {
$this->addNewUrl($event, $url);
}
}
foreach ($urlsFromDatabase as $url) {
$objectUrl = Url::ByUrl($url)->first();
if (!in_array($url, array_pluck($urlsFromWeb, 'url'))) {
$objectUrl->update(['is_active' => false]);
} else {
$objectUrl->update(['is_active' => true]);
}
}
}
$event->project->update(['is_crawlable' => false]);
}
示例8: dashboard
public function dashboard()
{
$view = [];
$days = 30;
$view['days'] = $days;
if (env('ANALYTICS_SITE_ID') == '') {
return view("mixdinternet/admix::dashboard", $view);
}
$graph = [];
$dataAnalytics = LaravelAnalytics::getVisitorsAndPageViews($days);
$graph['visitors'] = implode(',', array_pluck($dataAnalytics, 'visitors'));
$graph['pageViews'] = implode(',', array_pluck($dataAnalytics, 'pageViews'));
$carbonDate = array_pluck($dataAnalytics, 'date');
$date = [];
foreach ($carbonDate as $carbon) {
$date[] = $carbon->formatLocalized('%d/%m');
}
$graph['label'] = '"' . implode('","', $date) . '"';
$view['graph'] = $graph;
$view['direct'] = LaravelAnalytics::getTopReferrers($numberOfDays = $days, $maxResults = 10);
$view['mostVisited'] = LaravelAnalytics::getMostVisitedPages($numberOfDays = $days, $maxResults = 10);
$view['topBrowser'] = LaravelAnalytics::getTopBrowsers($numberOfDays = $days, $maxResults = 10);
$view['topKeywords'] = LaravelAnalytics::getTopKeywords($numberOfDays = $days, $maxResults = 10);
$dataAnalytics = LaravelAnalytics::performQuery(Carbon::now()->subDays($days), Carbon::now(), 'ga:pageviews');
$box['pageViews'] = $dataAnalytics['rows'][0][0];
$dataAnalytics = LaravelAnalytics::performQuery(Carbon::now()->subDays($days), Carbon::now(), 'ga:uniquePageviews');
$box['uniquePageviews'] = $dataAnalytics['rows'][0][0];
$dataAnalytics = LaravelAnalytics::performQuery(Carbon::now()->subDays($days), Carbon::now(), 'ga:avgTimeOnPage');
$box['avgTimeOnPage'] = Carbon::createFromTimestamp($dataAnalytics['rows'][0][0])->format('i:s');
$dataAnalytics = LaravelAnalytics::performQuery(Carbon::now()->subDays($days), Carbon::now(), 'ga:bounceRate');
$box['bounceRate'] = $dataAnalytics['rows'][0][0];
$view['box'] = $box;
return view("mixdinternet/admix::dashboard", $view);
}
示例9: make
public function make(array $data)
{
$otherSetting = $data['others'];
$categoryType = array_get($otherSetting['setting'], 'category');
$categoryLayer = config("module.category.layer.{$categoryType}");
$attributes = $this->attributes($data);
$categories = Categorize::getCategoryProvider()->root()->whereType($categoryType)->orderBy('sort', 'asc')->get();
$option = Categorize::tree($categories)->lists('title', 'id');
$form = '<select' . $attributes . '><option value="0">' . pick_trans('option.pleaseSelect') . '</option>';
if ($categoryLayer === 2) {
if (count($option)) {
foreach ($option as $key => $value) {
$category = Categorize::getCategoryProvider()->whereType($categoryType)->whereTitle($value)->first()->getChildren()->toArray();
$optgroup = $this->getSelectOptgroup($category['title']);
if (isset($category['children']) && count($category['children']) > 0) {
$form .= sprintf($optgroup, $this->getSelectOption($data, array_pluck($category['children'], 'title', 'id')));
} else {
$form .= $optgroup;
}
}
}
} else {
$form .= $this->getSelectOption($data, $option);
}
$form .= '</select>';
return $form;
}
示例10: __construct
public function __construct($name, $type, Form $parent, array $options)
{
/** @var Model $model */
$model = $options['model'];
$primary = $options['primary'];
$show = $options['show'];
$none_selected_item = isset($options['none_selected_item']) ? $options['none_selected_item'] : true;
/** Detect I18N */
$locale = Session::get('cms.locale', \Config::get('app.locale', 'en'));
$is_i18n = method_exists($model, 'saveI18N');
$query = $is_i18n ? $model::I18N($locale) : $model::query();
/** END **/
if (key_exists('filter', $options) && count($options['filter']) > 0) {
foreach ($options['filter'] as $key => $item) {
$query->where($key, $item['condition'], $item['value']);
}
}
/** Parse to key-name format {$table}.{$field} */
$keyName = strpos($options['primary'], '.') ? $options['primary'] : (new $model())->getTable() . "." . $options['primary'];
$data = $query->select($keyName, $show)->get()->toArray();
/** Fill model data to choice array */
$options['choices'] = [];
if ($none_selected_item) {
$options['choices'] = [null => ''];
}
$options['choices'] = $options['choices'] + array_pluck($data, $show, $primary);
/** END */
$options['selected'] = array_get($options, 'value', null);
parent::__construct($name, $type, $parent, $options);
}
示例11: __construct
public function __construct($upload_id)
{
parent::__construct('commercialauditing', $upload_id);
$regions = Config::get('plr.frontend.filter_order.commercial-auditing.region');
$regions = array_pluck($regions, 'dbLabel');
$this->string('country')->position(0);
$this->string('reference')->position(1)->insert();
$this->string('company')->position(2)->insert();
$this->string('brand')->position(3)->insert();
$this->string('product')->position(4)->insert();
$this->integer('spots')->position(5)->insert();
$this->seconds('airtime')->position(6)->insert();
$this->enum('region', $regions)->position(7);
$this->string('channel')->position(8);
$this->string('season')->position(9);
$this->integer('productcategory_id')->insert();
$this->integer('territory_id')->insert();
$this->integer('channel_id')->insert();
$this->integer('upload_id')->insert();
$this->integer('season_id')->insert();
$this->datetime('created_at', 'Y-m-d H:i:s')->insert();
$this->datetime('updated_at', 'Y-m-d H:i:s')->insert();
$this->relation('productcategories', 'productcategory_id')->field('name', 'product')->onBeforeInsert([$this, 'makeTimestamps']);
$this->relation('territories', 'territory_id')->field('name', 'country')->field('region', 'region')->onBeforeInsert([$this, 'makeAbb'])->onBeforeInsert([$this, 'makeTimestamps']);
$this->relation('channels', 'channel_id')->field('name', 'channel')->onBeforeInsert([$this, 'addUploadId'])->onBeforeInsert([$this, 'makeAbb'])->onBeforeInsert([$this, 'makeTimestamps']);
$this->relation('seasons', 'season_id')->field('name', 'season')->onBeforeInsert([$this, 'makeTimestamps']);
$this->on('parsed', [$this, 'makeTimestamps']);
}
示例12: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$user = $this->user->getById($id);
$roles = $this->role->getAll();
$user_roles = array_pluck($user->roles, 'id');
return view('admin/users/edit', compact('user', 'roles', 'user_roles'));
}
示例13: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$role = $this->role->getById($id);
$permissions = $this->perm->getAll();
$role_permissions = array_pluck($role->perms, 'id');
return view('admin/roles/edit', compact('role', 'permissions', 'role_permissions'));
}
示例14: store
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$order = new OrderDelay();
$order->fill($request->only('reason'));
$order->student_id = $this->student->id;
$order->academystructure_department_id = $this->student->academystructure_department_id;
$order->semester_id = $this->semester->id;
$order->state = 'تقديم';
$order->save();
// create order history record
$history = new Orderhistory();
$history->ref_key = 'order_delays';
$history->ref_value = $order->id;
$history->state = 'تقديم';
$history->save();
// check if financial item active then create debit record
$invoice_item = FinancialInvoiceItem::where('slug', 'delayed_fee')->where('state', 'نشط')->first();
if ($invoice_item) {
$invoice_data = ['ref_key' => 'order_delays', 'ref_value' => $order->id, 'student_id' => $this->student->id, 'amount' => $invoice_item->amount, 'type' => 'debit', 'semester_id' => $this->semester->id, 'item_id' => $invoice_item->id, 'note' => 'تكلفة طلب تاجيل دراسة'];
FinancialInvoice::create($invoice_data);
}
if ($request->has('files')) {
OrderFile::whereIn('id', array_pluck($request->input('files'), 'id'))->update(['ref_value' => $order->id, 'ref_key' => 'order_delays']);
}
$order->load('files');
return response()->json($order, 200, [], JSON_NUMERIC_CHECK);
}
示例15: testEndScope
public function testEndScope()
{
$before = array_pluck($this->test->get()->toArray(), 'item');
$this->assertContains('Another', $before);
$after = array_pluck($this->test->notEndingWith('her')->get()->toArray(), 'item');
$this->assertNotContains('Another', $after);
}