Questions tagged [pluck]

pluck is a Rails function used to query a single or multiple columns from the underlying table of a model.

pluck is a Rails function used to query a single or multiple columns from the underlying table of a model. It accepts a list of column names as argument and returns an array of values of the specified columns with the corresponding data type.

61 questions
25
votes
8 answers

In PHP, is there a function that returns an array made up of the value of a key from an array of associative arrays?

I'm sure this question has been asked before, my apologies for not finding it first. The original array: [0] => Array ( [categoryId] => 1 [eventId] => 2 [eventName] => 3 [vendorName] => 4 ) [1] => Array …
Caleb Gray
  • 2,930
  • 2
  • 19
  • 31
24
votes
4 answers

Laravel use of concat with pluck method

I am using Laravel.5.3 and below is my query $ProjectManagers = Employees::where("designation" , 1) ->pluck(DB::raw('CONCAT(first_name," ",last_name) AS name'),'id'); which throws an error that Illegal offset type in isset or empty May i know…
Punit Gajjar
  • 4,304
  • 7
  • 28
  • 61
19
votes
4 answers

Distinct values with pluck

I'm trying to retrieve data from database and bind them to a html select tag, and to bind them i need to use pluck so i get the field i want to show in a array(key => value), because of FORM::select. The normal pluck gets all the results, while i…
Arlind Hajdari
  • 385
  • 1
  • 3
  • 12
9
votes
5 answers

Pluck id (integer) cast to string Laravel

While plucking from a database, I get id as strings. $alphabets = new Alphabet(); return $alphabets->pluck('name', 'id'); Output { "1": "Apple", "2": "Ball", "3": "Cat" } Expected { 1: "Apple", 2: "Ball", 3: "Cat" } But,…
Sagar Chamling
  • 908
  • 10
  • 25
7
votes
3 answers

In Rails 3.2, how to "pluck_in_batches" for a very large table

I have a massive table Foo from which I need to pluck all values in a certain field, Foo.who. The array has millions of rows, but only a few thousand different values in the who column. If the table was smaller of course I'd simply use…
jpw
  • 17,034
  • 21
  • 104
  • 164
4
votes
2 answers

Add lists() method in Query Builder in Laravel 5.4

I know the fact that Laravel has removed lists() function and moved functions signature as pluck(). But, this leads to a lot of work for someone who wants to Upgrade from Laravel 4.x to Laravel 5.4. Hence, I am trying to find a way to just make…
Ateeq Ahmed
  • 111
  • 1
  • 7
3
votes
1 answer

Using map and pluck to get values from nested list

I have the following nasty, nested list Edit: updated to include value_I_dont_want mylist <- list( list( nested_1 = list( nested_2 = list( list( value_I_want = "a", value_I_dont_want = "f"), list( value_I_want = "b",…
MayaGans
  • 1,507
  • 3
  • 17
3
votes
3 answers

Laravel pluck Array to string conversion

I am create complaint For that while inserting department for their complaint I am using pluck() method to retrieve data from department table and display complaint in select dropdown as array but the problem is it is not working as it says Array…
story ks
  • 644
  • 9
  • 30
2
votes
4 answers

purrr::pluck - how to get last element of list

I am trying to extract the last element of nested lists. How can I do this with purrr? In the example below the results should be all the elements with the value "c". I have seen this, but I am particularly interested in a solution with purrr. Many…
zoowalk
  • 1,570
  • 13
  • 25
2
votes
1 answer

Typescript: Using a tuple as index type

Given is a tuple of some keys like ["a", "b", "c"] and a nested object with those keys as properties {a: {b: {c: number}}}. How do you recursively use the members of the tuple as index in typescript? A implementation without proper typing: function…
MaximilianMairinger
  • 1,308
  • 1
  • 9
  • 27
2
votes
1 answer

Is there a way to (re)map Laravel Collections with an index from its content?

I have some Newsletters: $newsletters = $channel->Newsletter()->whereIn('id', $wantNewsletters)->get(); Which result in this collection: I tried to use pluck, but it just allows one column: $newsletters = $channel->Newsletter()->whereIn('id',…
andi79h
  • 786
  • 8
  • 17
2
votes
0 answers

CKeditor integration throwing Uncaught RangeError: Maximum call stack size exceeded. on focus of text area

I am working on pluck integration with our ecommerce site - Pluck integration forums include a ckeditor where a user can type and post in to a forum. But with our integration, upon clicking the ck editor text area i am getting the following…
2
votes
1 answer

rails4 pluck with order and limit

In my sidebar I display the freshly created user profiles. Profile belongs_to user and user has_one_profile. I realized that I only use 3 columns from the profile table so it would be better to use pluck. I also have a link_to…
Sean Magyar
  • 2,230
  • 15
  • 43
1
vote
1 answer

Laravel pluck, groupBy custom date Format

Can't Format created_at when use pluck. VisitorsStatistic::where('landing_page_id', $this->landing_page->id) ->select('created_at', DB::raw('count(*) as visitors')) ->whereMonth('created_at', '>=', $this->start_month) …
Aciddiz
  • 97
  • 9
1
vote
1 answer

Using map to pluck from nested list

I'm trying to familiarize myself with purrr, map and pluck and I have a deeply nested list: test_list <- list( outer_1 = list( list( inner_1 = list(pluck = "String I Want", dontpluck = "other string") ) ) …
MayaGans
  • 1,507
  • 3
  • 17
1
2 3 4 5