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.

69 questions
0
votes
1 answer

Laravel 5.5, Collections and Localization

This question is a follow-up/attempt to implement the answer from a prior question. My attempt to pluck values from a collection and apply the current localization is as follows: $prefix_array = ['' => trans('registration.prefixes.select')] + …
Phil
  • 320
  • 4
  • 16
0
votes
2 answers

Laravel: get name from table users

I need get the name field in user table My method in the controller: public function reviewsactivity() { $activity = Activity::orderBy('id', 'DESC')->paginate(); $users = User::orderBy('id', 'ASC')->pluck('id', 'name'); return…
Drennos
  • 303
  • 2
  • 6
  • 16
0
votes
1 answer

Rails pluck from associated tables

I have two tables sample has_many :abundances self.primary_key = :sample_id and abundance has_many :samples self.primary_key = :sample_id In abundances controller i have a ransack search def index @search =…
Ahk86
  • 177
  • 2
  • 11
0
votes
2 answers

Laravel 5.4 skip first value in Pluck array

I have this query $orderStates = OrderState::listsTranslations( 'states' )->pluck( 'states', 'id' )->toArray(); which will output something like array:3 [▼ 1 => "waiting" 2 => "agreed" 3 => "canceled" ] I need to skip the first one to be…
Yousef Altaf
  • 2,631
  • 4
  • 46
  • 71
0
votes
1 answer

Laravel5: How to access paginated data before passing it to blade

I fetch some data with $merchants = Merchant::selectRaw($query)->with(...)->whereHas(...)->where(...)->paginate(10); Now, I want to pluck() this data before passing it to blade. This doesn't work: $collection = collect($merchants); When I fetch…
Dong3000
  • 566
  • 2
  • 7
  • 24
0
votes
1 answer

How does pluck hook work in feathersjs

In the feathersjs docs the explanation provided is as follows: pluck discards all fields except for the specified ones, either from the data submitted or from the result. If the data is an array or a paginated find result the hook will remove…
0
votes
1 answer

Laravel5.3:How to use pluck in relationship for bindign Form::select element?

This is my model: class Positions extends Model implements Repository { protected $fillable = ['index_id', 'title', 'description']; public function index() { return $this->belongsTo('TEST\Indices', 'index_id'); } public…
Rohullah Rajaee Rad
  • 571
  • 2
  • 9
  • 33
0
votes
1 answer

Ramda.js pluck(key) type vs native map

Say I have the following code: const results = //some complex datastructure generated by a third party api call const reducedList = results.map((item) => item.awesome_key) .map((awesomeKeyList) => awesomeKeyList .reduce((memo, awesomeKey) =>…
Abraham P
  • 15,029
  • 13
  • 58
  • 126
0
votes
3 answers

How to display ROR 5 ActiveRecord pluck as String in html.erb

In html.erb I have: <%= ContactDescribe.where(["contact_describe_id = ?", "12"]).limit(1).pluck(:borrower_or_lender_text) %> The field is retrieved successfully. But returns an array element. I need to learn how to convert that element to a…
emm
  • 19
  • 1
  • 6
0
votes
2 answers

Laravel 5.4 pluck, where

I'm working on an assignment system for radio newscasts. Trying to return a view of all assignments for a particular newscast, and I'm stymied. Tables users table id | name ---|------- 1 | Admin 2 | Susan 3 | Ed 4 | Jen newscasts table …
Scott Roberts
  • 13
  • 1
  • 7
0
votes
2 answers

Laravel Plucking 5.4 error variable undefined

Error churchdetails is not defined: This is the pastorController public function index() { $pastors = Pastor::all(); $churchdetails = Church::all()->pluck('church_name','church_address'); return…
Lois Arce
  • 69
  • 1
  • 1
  • 7
0
votes
4 answers

Using Laravel's pluck method without an associative array

Let's say I've got an Articles collection, and I want to fetch the popular articles. So first, I make a scopePopular() method in the Article method. Very simple. Now I want to fetch their ids, so I'll do this: Article::popular->pluck('id'); The…
Eliya Cohen
  • 10,716
  • 13
  • 59
  • 116
0
votes
1 answer

How to pick a property with the value in an array?

Here I have an array with many objects. In that I have a field as "id". I want only the id which has a value as null. How to pick it? $scope.hierarchyList = response.data; So how to pluck the value?
Vignesh
  • 1
  • 4
0
votes
1 answer

Laravel form face use $key => $value ($value2) instead of $key => $value

Sorry if the title is misleading... I have the following to create a select box using the laravel Form facade: {{ Form::select('category_select', $categories_select, null, array('class' => 'selectpicker show-tick', 'data-live-search' => 'true',…
xTheWolf
  • 1,756
  • 4
  • 18
  • 43
0
votes
1 answer

How to use only use .pluck to grab the first x amount of records?

Can .pluck be used to get say only the first 5 values e.g. CategoryItemKey.where(category_id: @category.id).pluck(:name) I only want the first 5 names. Also if there are only 3 names it wont throw an error it will just grab 3. Cant see it in the…
Rob
  • 1,835
  • 2
  • 25
  • 53