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
1
vote
4 answers

Laravel - pluck with specified keys

I have a line of code similar to the following: Sport::pluck('id', 'name) I am dealing with frontend JavaScript that expects a list in this format: var list = [ { text: 'Football', value: 1 }, { text: 'Basketball', value: 2 }, { text:…
Barry D.
  • 413
  • 2
  • 4
  • 17
1
vote
1 answer

Laravel Pluck Selected option

i wants to show selected category option in Sub-category edit form. Am using pluck function for fetch category from database. {{ Form::model($subcategories,['route'=> ['subcategories.edit',$subcategories->id],'method'=>'post']) }}
Ripon Uddin
  • 482
  • 2
  • 10
  • 21
1
vote
1 answer

Eloquent: Retrieve pluck collection with trashed entries

I want to get all Address IDs, including the trashed ones, with pluck. This is how it is working but I don't get the trashed ones as well...: $clientIDs = Client::pluck('address_id')->all(); This is what I tried already: $clientIDs =…
Jan
  • 960
  • 1
  • 13
  • 32
1
vote
0 answers

Laravel 5.4 join concat pluck

I am writing an assignment system for biodata record. The data tables: preceptorids preceptorids_id | bio_id | preceptors_status ----------------| --------------------------- 1 | 5 | 3 bios bio_id | bio_thana | boi_chaya…
1
vote
2 answers

How to get all the values of single column using laravel 4.2

I am using pluck method to get data from single column $systems = OptionUser::pluck('user_skill'); This systems variable returning only one value while I have around 50 values in this table. Please suggest what is correct way to get all the data…
Ramkishan Suthar
  • 353
  • 1
  • 6
  • 21
1
vote
2 answers

Laravel 5.3 select pluck method

Controller method: public function edit($id){ $match2 = Match::pluck('team_a_id', 'id'); return view('admin.accept.edit', compact('match2')); } And view file: {{ Form::select('matches_id', $match2, null, ['class' => 'form-control'])…
michal
  • 940
  • 13
  • 29
1
vote
1 answer

Using Wikipedia-Client Gem to Update Rails Database

My ruby and Rails is a bit rusty. I have a table in my database called institutes which has some of the columns filled. I want to use the Wikipedia-Client gem to fill some of the others. I want to use the name attribute to find the page on Wikipedia…
Dave C
  • 347
  • 3
  • 16
1
vote
2 answers

rails, form select, pluck 2 fields

I'm trying to simply display 2 fields (first name and last name) in a form select (f.select). Here is my code: <%= f.select :person, User.where(verified_person: 't').pluck(:first_name, :last_name) %> With the code above, the select drop-down field…
gitastic
  • 362
  • 5
  • 23
1
vote
1 answer

How to get an object from an array Ruby on Rails

In controller I use pluck method to get id and name from my database @user1 = User.where(name: 'Alex').pluck(:id, :name).first @user2 = User.where(name: 'Alex').pluck(:id, :name) It return array @user1 = `[3, 'Alex']` @user2 = [[3,'Alex'],[4,…
user3563581
  • 67
  • 1
  • 5
1
vote
2 answers

Neo4j gem - Plucking multiple nodes/relationships

This may not be possible as it is right now but I have a query like so events = Event.as(:e).where("(( e.date_start - {current_time} )/{one_day_p}) < 1 ").users(:u, :rel).where("rel.reminded = {reminded_p}" ).params(reminded_p: false, one_day_p:…
Clam
  • 905
  • 1
  • 11
  • 24
1
vote
4 answers

Retrieving multiple Records,columns using Joins and pluck

I found a weird behaviour from Active Record Pluck. My query is Friend.joins('INNER JOIN users ON friends.friend_id = users.id').where("user_id=? AND (status=? or status=?)", 4,"true","").pluck("users.first_name, users.last_name") It is to join…
santosh
  • 1,613
  • 1
  • 12
  • 19
1
vote
2 answers

underscorejs pluck two dimensional array

First time using underscore and I am stuck and cannot find an example. My data is: [{ "store_name": "Store 1", "franchisee_id": "id01", "dish_menu": "Breakfast", "dish_count": "17" }, { "store_name":…
TheRealPapa
  • 3,783
  • 6
  • 49
  • 125
0
votes
1 answer

Laravel whereIn doesn't return all data

I have following array (created by explode method) ["3D Printing"," 3D Architecture"," .NET Micro Framework"] when I try to match this titles to my database and get id of each of them, I only get id of first…
mafortis
  • 5,003
  • 10
  • 59
  • 163
0
votes
0 answers

Using WhereNotIn with pluck won't let show the old value in edit blade?

I know exactly how WhereNotIn is working but still I need it to make my list remove the values which is taken, in my case I want to edit using WhereNotIn and show me the value which I chose before + not taken values is there is a way to implement…
Tinkerbell
  • 13
  • 1
  • 5
0
votes
1 answer

Pluck the values from WITH Eloquent in Laravel

I have a dropdown box that shows only the user with collector and borrower's role. Here's my code public function create() { $users = User::whereHas('roles', function ($q) { $q->where('roles.name', '=',…
Lito
  • 533
  • 1
  • 5
  • 24