skip to Main Content

On laravel I have 2 requests :

$interviewers = Interviewer::get()->pluck('name', 'id');
$defaultInterviewers = UserMeetingInterviewer::getUserMeetingId($this->record->id)->get()->pluck('id');

How to leave in $interviewers only values which exists in $defaultInterviewers ?
Sure I know how use foreach with new var, I mean methods from https://laravel.com/docs/10.x/helpers...
I did not find…

"laravel/framework": "^10.35.0"

Thanks in advance!

2

Answers


  1. $interviewers = Interviewer::whereIn('id',$defaultInterviewers)->get()->pluck('name', 'id');
    

    Move the $interviewers one step down. As you are not using anywhere in the $defaultInterviewers.

    Login or Signup to reply.
  2. intersect method should work

    but you have to put $interviewers after $defaultInterviewers

    $defaultInterviewers = UserMeetingInterviewer::getUserMeetingId($this->record->id)->get()->pluck('id');
    
    $interviewers = Interviewer::get()->pluck('name', 'id')->intersect($defaultInterviewers);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search