public function store() { $hasDemographics = Input::hasFile('demographics'); $hasRates = Request::hasFile('rates'); $destination = public_path() . "/advertising/"; $demographics_uploaded = false; $rates_uploaded = false; /* Retrieve current data from database, If there is current data, then there will only be ONE row. * Otherwise, we will create a row and insert the data provided by the user. */ $advertising = Advertising::first(); if (!$advertising) { if ($hasDemographics && $hasRates) { $advertising = Advertising::create(Input::only(['demographics', 'rates'])); } else { if ($hasDemographics) { $advertising = Advertising::create(Input::only('demographics')); } else { if ($hasRates) { $advertising = Advertising::create(Input::only('rates')); } else { if (!$hasDemographics && !$hasRates) { return Redirect::to('admin/advertising/add', ['error' => 'Demographics or Rates must be provided!', 'demographics' => $advertising->demographics, 'rates' => $advertising->rates]); } } } } } /* The following two blocks are for handling uploading of the PDF files. * The best way I can figure is to handle on after another, not dependent upon eachother. Previous attempts * with other ways were not successful. */ if ($hasDemographics) { if (Input::file('demographics')->isValid()) { $demographics = Input::file('demographics')->getClientOriginalName(); $demographics_uploaded = Request::file('demographics')->move($destination, $demographics); //dd($demographics_uploaded); if ($demographics_uploaded) { $advertising->demographics = $demographics; $savedDemographics = $advertising->save(); } } } if ($hasRates) { if (Input::file('rates')->isValid()) { $rates = Input::file('rates')->getClientOriginalName(); $rates_uploaded = Request::file('rates')->move($destination, $rates); //dd($rates_uploaded); if ($rates_uploaded) { $advertising->rates = $rates; $savedRates = $advertising->save(); } } } if ($hasDemographics && !$demographics_uploaded) { $error .= " Demographics upload was unsuccessful!"; } else { if ($hasRates && !$rates_uploaded) { $error .= " Rates upload was unsuccessful!"; } else { $error = 'none'; } } if ($error != 'none') { return View::make('/admin/advertising/add', ['error' => 'Upload was unsuccessful!', 'demographics' => $advertising->demographics, 'rates' => $advertising->rates]); } else { return View::make('/admin/advertising/index', ['error' => 'none', 'demographics' => $advertising->demographics, 'rates' => $advertising->rates]); } }