/** * Show the form for creating a new resource. * * @return Response */ public function create($distPlanID) { //To remove duplicate, get agent NOT listed in $distPlanID $addedAgents = DistPlanDet::with('agent')->where('distribution_plan_id', '=', $distPlanID)->get(); //Convert to array $agents = []; foreach ($addedAgents as $detail) { $agents[] = $detail->agent->id; } $unAssignedAgent = Agent::select('id', 'name')->whereNotIn('id', $agents)->get(); return view('circulation/distribution-plan-details-form', ['agents' => $unAssignedAgent, 'distPlanID' => $distPlanID, 'form_action' => action("DistributionPlanDetController@store", [$distPlanID])]); }