Esempio n. 1
0
 public function store()
 {
     $filesystem = new Filesystem();
     $advertising = Advertising::where('name', '=', Input::get('name'));
     if (!$advertising->count() > 0) {
         $advertising = Advertising::create(['name' => Input::get('name'), 'bio' => Input::get('bio')]);
     }
     if (Input::has('image')) {
         $destination = public_path() . "/images/advertising/";
         $filename = Input::file('image');
         $file = $filesystem->move($destination, $filename);
         if ($file) {
             $advertising->image = $filename;
         }
         $advertising->save();
     }
     if ($advertising) {
         return Redirect::to('admin/advertising/' . $advertising->id . '/show', ['advertising' => $advertising, 'add_failed' => 'false']);
     }
     return View::make('admin.advertising.add', ['add_failed' => 'true']);
     /*
             if (\Input::get('name')) {
                 $filesystem = new Filesystem;
                 $advertising = \Advertising::findOrCreate(\Input::get('name'));
                 //$advertising_exists = \Advertising::where('name', '=', \Input::get('name'));
                     if ($exists->id) {
                         return \View::make('admin.advertising.add', ['add_failed'=> 'true', 'error_msg' => 'An entry for this advertising already exists!']);
                     }
                     //$new_advertising = \Advertising::create(\Input::only(['name', 'image', 'bio']));
                     $advertising->name = \Input::get('name');
                     $advertising->bio = \Input::get('bio');
     
                     if (\Input::has('image')) {
                         $destination = public_path() . "/images/advertising/";
                         $filename = \Input::file('image');
                         $upload_success = $filesystem->move($destination, $filename);
                         //$upload_success = \Input::file('image')->move($destinationPath, $filename);
                         if ($upload_success) {
                                $advertising->image = $filename;
                         }
                     }
                     $advertising->save();
                     return \View::make('admin.advertising.add', ['add_failed' => 'true']);
     
             }*/
 }
 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]);
     }
 }