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
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',…
0
votes
0 answers

How to pluck in Mongoose

Hello there my good people. I have started using Mongoose and I am trying to pluck some items, the way I do it when I work in laravel. I am building a podcast aggregator. Here is the User model. The user logs into the system: const userSchema =…
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
  • 159
  • 1
  • 10
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…
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
  • 147
  • 7
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,646
  • 1
  • 4
  • 13
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
  • 424
  • 6
  • 19
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
  • 9
  • 3
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…
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
  • 182
  • 2
  • 13
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
  • 141
  • 1
  • 2
  • 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
  • 125
  • 1
  • 8
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,176
  • 4
  • 41
  • 62
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
  • 556
  • 1
  • 4
  • 21
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…
{{ $user->roles()->pluck('name')->implode(' ') }}