public function retrievePostPDF() { $validator = Validator::make(Input::all(), array('packinglist' => 'required')); if (!$validator->fails()) { include app_path() . '/includes/PDFMerger.php'; $notFoundPOs = array(); $nonGroundPOs = array(); $packingListPOsArray = array(); $packingListPathArray = array(); $packingListPOs = trim(Input::get('packinglist')); Session::flash('packinglist', $packingListPOs); $packingListPOsArray = explode(PHP_EOL, $packingListPOs); foreach ($packingListPOsArray as $packingListPO) { $tempPackingList = PackingList::where('po', '=', $packingListPO)->first(); if ($tempPackingList == null) { //do not have packing list yet array_push($notFoundPOs, $packingListPO); } else { array_push($packingListPathArray, $tempPackingList->pathToFile); // dd($tempPackingList->shipterms=='Ground'); if ($tempPackingList->shipterms != 'Ground') { array_push($nonGroundPOs, $packingListPO); } } } if (count($notFoundPOs) > 0) { $notFoundPOsReturnString = ''; foreach ($notFoundPOs as $notFoundPO) { $notFoundPOsReturnString .= $notFoundPO . '<br>'; } return View::make('parsepdfKohls-exportpdf-output')->with(array('response' => '<p style="color:red;">The below POs are missing:</p><br>' . $notFoundPOsReturnString)); } else { //return a download file..we have all Packing lists $pdf = new PDFMerger(); foreach ($packingListPathArray as $packingListPath) { $pdf->addPDF($packingListPath); } $tempoutputpath = 'output' . '-' . time() . '.pdf'; $outputpath = public_path() . '/Kohlspos/' . $tempoutputpath; $pdf->merge('file', $outputpath); $outputpath = 'Kohlspos/' . $tempoutputpath; $data['nonGroundPos'] = $nonGroundPOs; // dd($nonGroundPOs); $data['outputpath'] = $outputpath; return View::make('parsepdfKohls-exportpdf-output', $data); // REPLACE 'file' WITH 'browser', 'download', 'string', or 'file' for output options } } else { return View::make('parsepdfKohls-exportpdf-input')->with(array('response' => '<p style="color:red;">Please add a list of POs below.</p>')); } }