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
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
  • 4,393
  • 8
  • 71
  • 155
0
votes
1 answer

Larvel Query Builder group By with pluck

id agent_id currency 1 A0001 IDR 2 A0002 MYR 3 A0001 THB example currently have a dataset as above, is it have any way to using only 1 query builder to get the outcome like below Output: [ "agent_id" => "A0001", …
Wei Kang
  • 163
  • 2
  • 9
0
votes
1 answer

Laravel Pluck and combine two fields to generate a select menu

Let's say I have the following fields in my database for a user, id, first_name and last_name. I want to generate a select menu, something like below: I know I can use pluck…
Hardist
  • 2,098
  • 11
  • 49
  • 85
0
votes
1 answer

How to format date when using pluck in Rails

My User model looks like this. User has many attached Resume. class User < ApplicationRecord has_many_attached :resumes, dependent: :destroy end Now in different form, I want to show list of resumes upload by user in descending order. I manage to…
r3b00t
  • 6,953
  • 6
  • 27
  • 37
0
votes
1 answer

Ruby on Rails using pluck to select singular dates from table?

Hi I am trying to build a rails meetings application. I have aa table called Meetings with 4 columns name:string start_date:datime end_date:datetime duration:integer A meeting will have multible inputs per day for example a person can have two or…
Sarah Duffy
  • 191
  • 3
  • 14
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
  • 6,750
  • 23
  • 130
  • 288
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', '=',…
SleepWalker
  • 613
  • 1
  • 12
  • 39
0
votes
1 answer

in_array() expects parameter 2 to be array, object given

i know this is similar with other question, but. how if we get the data array from db and try to compare those data ? $x = Video::where('kursus_id', $data)->pluck('slug'); $z = Video::where('kelas_id', $data_id_kelas) ->where('mapel_id',…
Febri Tahta
  • 95
  • 1
  • 7
0
votes
2 answers

Laravel Pluck from 'with relation'

Need to have a pluck from with relation. I'm sharing code below. My controller: $type = StandType::with(['brieftype' => function($q) use ($brief_id){ $q->where('brief_id', $brief_id); }])->get()->keyBy('name'); My Model: public…
TCS
  • 629
  • 3
  • 11
  • 32
0
votes
1 answer

Rails using joins retrieve repeated column

My association class Website < ApplicationRecord has_many :settings has_one :shop end Setting and Shop tables value are: 2.6.1 :003 > Setting.all.pluck(:records) => [2, 2, 4, 0, 0, 0] 2.6.1 :003 > Shop.all.pluck(:records) => [4, 1, 1] Using…
Nikund Lathiya
  • 79
  • 2
  • 10
0
votes
1 answer

Laravel Pluck items onto new table rows

I have a table for trips and a table for events. One trip can have many events. When editing a trip i want to display a table showing the event name, start date end date. I have been using pluck to get data: -
Laura
  • 117
  • 1
  • 12
0
votes
0 answers

how to retrieve values from collections laravel

the problem is, when I pluck the ids, a collection of ids returned I need to get only the values $transferOfficeId = $searchResults->pluck('office_id','office_id'); $vehicleId = $searchResults->pluck('vehicle_id','vehicle_id'); $agencyId =…
Sohaib
  • 1,972
  • 3
  • 9
  • 19
0
votes
2 answers

How to catch 1 colomn (id) on table in edit form

I have 1 table data . and I have function edit on this table . in this edit form I have select dropdown to show pluck from database . I have 3 table . this name is aduan, ipsrs , teknisi struckture aduan table id…
Adhik Mulat
  • 538
  • 2
  • 10
  • 39
0
votes
2 answers

Laravel 5.8 - Get values from pluck result

I need help to make this code work. After make a search by a Software, my controller return the locals who have the software instaled, and the S.O. who has the same. For exemple, this query will return "1 2", because this two images has "Google…
Gelbcke
  • 11
  • 4
0
votes
2 answers

Laravel and spatie/laravel-permission - plucking names of roles to a view

I want in Laravel to "pluck" to the view names of roles, each in different badge. My code:
My result: I am getting all role names in one span…
Tomek Greber
  • 5
  • 1
  • 7
{{ $user->roles()->pluck('name')->implode(' ') }}