/**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $class = NavBar::find($id);
     if ($class->delete()) {
         return Response::json('success', 200);
     } else {
         return Response::json('error', 400);
     }
 }
 public function run()
 {
     DB::table('locations')->delete();
     $locations = ['Brookhaven' => ['street_address' => '19 E. Lincoln Road NE', 'locality' => 'Brookhaven', 'region' => 'Mississippi', 'postal_code' => '39601', 'country_name' => 'United States', 'latitude' => 31.552175, 'longitude' => -90.387171, 'phone' => '(601) 823-6516', 'fax' => '', 'email' => '', 'directions' => 'One mile east of Highway 36 on FM 18', 'facebook' => 'https://www.facebook.com/ReedsMetals', 'twitter' => '', 'google_plus' => '', 'bbb' => 'http://www.bbb.org/mississippi/business-reviews/buildings-pre-cut-prefab-and-modular-dealers/reed-s-metals-inc-in-brookhaven-ms-6001105', 'purechat_id' => 'fb810597-8a5e-46e7-8306-35f568c2981a', 'hours' => [[8, 17], [8, 17], [8, 17], [8, 17], [8, 17], [0, 0]], 'employees' => ['David Forehand', 'Stephen Foreman', 'Adam Humphrey', 'Jason Henderson', 'Laraye Waldrop', 'Clayton Reed', 'Graham Parker', 'Joe Lea', 'Kara Tate', 'Ira Ott', 'Jessica Breazeale', 'Steve Ham', 'Matthew Martin', 'Ken Byrd', 'Josh Gordon', 'Kasie Duval', 'Carly Brooke Waldrop', 'Erin Johnson', 'Melissa Lambert', 'Laina Watts', 'Rosiland Lipscomb', 'Kelly Dunaway', 'Hope Johnston', 'Destiny Wallace']], 'Lake Charles' => ['street_address' => '1909 Ruth Street', 'locality' => 'Sulphur', 'region' => 'Louisiana', 'postal_code' => '70663', 'country_name' => 'United States', 'latitude' => 30.220561, 'longitude' => -93.37866099999999, 'phone' => '(337) 625-5051', 'fax' => '', 'email' => '', 'directions' => '', 'facebook' => 'https://www.facebook.com/reedsmetalsofsulphur', 'twitter' => '', 'google_plus' => '', 'bbb' => 'http://www.bbb.org/lakecharles/business-reviews/buildings-metal/reeds-metals-of-sulphur-in-sulphur-la-90005404', 'purechat_id' => '', 'hours' => [[8, 17], [8, 17], [8, 17], [8, 17], [8, 17], [0, 0]], 'employees' => ['Randle Reed', 'Nilah Reed', 'Paul Richardson', 'Lewis', 'Lee Fewell', 'Sharrie Kyle', 'Melissa Forrest', 'Paislee Fruge', 'Mark Mattingly']], 'Tupelo' => ['street_address' => '120 Industrial Park Road', 'locality' => 'Saltillo', 'region' => 'Mississippi', 'postal_code' => '38866', 'country_name' => 'United States', 'latitude' => 34.361126, 'longitude' => -88.702369, 'phone' => '(662) 869-7797', 'fax' => '', 'email' => '', 'directions' => '', 'facebook' => 'https://www.facebook.com/Reeds-Metals-TupeloJackson-113853862046958/', 'twitter' => '', 'google_plus' => '', 'bbb' => 'http://www.bbb.org/mississippi/business-reviews/buildings-pre-cut-prefab-and-modular-dealers/reed-s-metals-inc-in-brookhaven-ms-6001105', 'purechat_id' => '', 'hours' => [[8, 17], [8, 17], [8, 17], [8, 17], [8, 17], [0, 0]], 'employees' => ['Daniel Butler', 'Jeremy Butler', 'Jennifer Gresham', 'Paden McCullough', 'Aaron Carter', 'Tony Burcham', 'Tim Hartwig', 'Wesley Raines', 'Malaya']], 'Benton' => ['street_address' => '12655 Interstate 30 South', 'locality' => 'Benton', 'region' => 'Arkansas', 'postal_code' => '72015', 'country_name' => 'United States', 'latitude' => 34.540193, 'longitude' => -92.646573, 'phone' => '(501) 776-3825', 'fax' => '', 'email' => '', 'directions' => '', 'facebook' => '', 'twitter' => '', 'google_plus' => '', 'bbb' => 'http://www.bbb.org/arkansas/business-reviews/buildings-metal/reeds-metals-of-benton-ar-in-benton-ar-90276734', 'purechat_id' => '', 'hours' => [[7.5, 18], [7.5, 18], [7.5, 18], [7.5, 18], [7.5, 18], [8, 12]], 'employees' => ['Mark Barnett', 'Dayna Barnett', 'Anthony Jasay', 'Ricky Thacker', 'Jim Carson', 'Swade Scott', 'Brent Galloway', 'Rusty George', 'Diana Young', 'Katie Nioxn']], 'Jackson' => ['street_address' => '1070 South Highland Ave', 'locality' => 'Jackson', 'region' => 'Tennessee', 'postal_code' => '38301', 'country_name' => 'United States', 'latitude' => 35.586104, 'longitude' => -88.81350399999999, 'phone' => '(731) 300-3200', 'fax' => '', 'email' => '', 'directions' => '', 'facebook' => 'https://www.facebook.com/Reeds-Metals-TupeloJackson-113853862046958/', 'twitter' => '', 'google_plus' => '', 'bbb' => 'http://www.bbb.org/mississippi/business-reviews/buildings-pre-cut-prefab-and-modular-dealers/reed-s-metals-inc-in-brookhaven-ms-6001105', 'purechat_id' => '', 'hours' => [[8, 17], [8, 17], [8, 17], [8, 17], [8, 17], [0, 0]], 'employees' => ['Joanna Carroll', 'Ricky Fischer', 'Andrew Lindsey', 'Bill Rosson', 'Kelli English']], 'Holden' => ['street_address' => '27844 James Chapel Rd N', 'locality' => 'Holden', 'region' => 'Louisiana', 'postal_code' => '70744', 'country_name' => 'United States', 'latitude' => 30.475168, 'longitude' => -90.621866, 'phone' => '(225) 209-1010', 'fax' => '', 'email' => '', 'directions' => '', 'facebook' => 'https://www.facebook.com/ReedsMetals', 'twitter' => '', 'google_plus' => '', 'bbb' => 'http://www.bbb.org/mississippi/business-reviews/buildings-pre-cut-prefab-and-modular-dealers/reed-s-metals-inc-in-brookhaven-ms-6001105', 'purechat_id' => 'fb810597-8a5e-46e7-8306-35f568c2981a', 'hours' => [[8, 17], [8, 17], [8, 17], [8, 17], [8, 17], [0, 0]], 'employees' => [], 'parent' => 'Brookhaven'], 'Meridian' => ['street_address' => '5321 Arundel Rd', 'locality' => 'Meridian', 'region' => 'Mississippi', 'postal_code' => '39307', 'country_name' => 'United States', 'latitude' => 32.350914, 'longitude' => -88.730953, 'phone' => '(601) 482-1500', 'fax' => '', 'email' => '', 'directions' => '', 'facebook' => 'https://www.facebook.com/ReedsMetals', 'twitter' => '', 'google_plus' => '', 'bbb' => 'http://www.bbb.org/mississippi/business-reviews/buildings-pre-cut-prefab-and-modular-dealers/reed-s-metals-inc-in-brookhaven-ms-6001105', 'purechat_id' => 'fb810597-8a5e-46e7-8306-35f568c2981a', 'hours' => [[8, 17], [8, 17], [8, 17], [8, 17], [8, 17], [0, 0]], 'employees' => [], 'parent' => 'Brookhaven'], 'Jasper' => ['street_address' => '3931 Hwy 96 S', 'locality' => 'Jasper', 'region' => 'Texas', 'postal_code' => '75951', 'country_name' => 'United States', 'latitude' => 30.866543, 'longitude' => -93.979141, 'phone' => '(409) 384-5777', 'fax' => '', 'email' => '', 'directions' => '', 'facebook' => 'https://www.facebook.com/ReedsMetals', 'twitter' => '', 'google_plus' => '', 'bbb' => 'http://www.bbb.org/lakecharles/business-reviews/buildings-metal/reeds-metals-of-sulphur-in-sulphur-la-90005404', 'purechat_id' => '', 'hours' => [[8, 17], [8, 17], [8, 17], [8, 17], [8, 17], [0, 0]], 'employees' => [], 'parent' => 'Lake Charles']];
     $dirname = dirname(__FILE__);
     $logoSize = filesize($dirname . "/default_images/reeds-logo.png");
     foreach ($locations as $locationName => $locationInfo) {
         // Create logo
         copy($dirname . "/default_images/reeds-logo.png", $dirname . "/ReedsLogo.png");
         $file = new UploadedFile($dirname . "/ReedsLogo.png", "ReedsLogo.png", "image/png", $logoSize, null, true);
         $logoImage = ImageList::upload($file);
         // Create aerial photo
         if (file_exists($dirname . "/default_images/" . $locationName . ".jpg")) {
             copy($dirname . "/default_images/" . $locationName . ".jpg", $dirname . "/Aerial-" . $locationName . ".jpg");
         } else {
             copy($dirname . "/default_images/default.jpg", $dirname . "/Aerial-" . $locationName . ".jpg");
         }
         $file = new UploadedFile($dirname . "/Aerial-" . $locationName . ".jpg", "/Aerial-" . $locationName . ".jpg", "image/jpeg", $logoSize, null, true);
         $aerialImage = ImageList::upload($file);
         // Create home page
         $homePage = new HomePage();
         // Create home page slider
         $slider = new Slider();
         $slider->save();
         // Create nav bar
         $navBar = new NavBar();
         $location = Location::firstOrCreate(['name' => $locationName, 'phone' => $locationInfo['phone'], 'fax' => $locationInfo['fax'], 'email' => $locationInfo['email'], 'directions' => $locationInfo['directions'], 'street_address' => $locationInfo['street_address'], 'locality' => $locationInfo['locality'], 'region' => $locationInfo['region'], 'postal_code' => $locationInfo['postal_code'], 'country_name' => $locationInfo['country_name'], 'latitude' => $locationInfo['latitude'], 'longitude' => $locationInfo['longitude'], 'delivery_distance' => 100, 'facebook' => $locationInfo['facebook'], 'twitter' => $locationInfo['twitter'], 'google_plus' => $locationInfo['google_plus'], 'bbb' => $locationInfo['bbb'], 'purechat_id' => $locationInfo['purechat_id'], 'monday_open' => $locationInfo['hours'][0][0], 'monday_close' => $locationInfo['hours'][0][1], 'tuesday_open' => $locationInfo['hours'][1][0], 'tuesday_close' => $locationInfo['hours'][1][1], 'wednesday_open' => $locationInfo['hours'][2][0], 'wednesday_close' => $locationInfo['hours'][2][1], 'thursday_open' => $locationInfo['hours'][3][0], 'thursday_close' => $locationInfo['hours'][3][1], 'friday_open' => $locationInfo['hours'][4][0], 'friday_close' => $locationInfo['hours'][4][1], 'saturday_open' => $locationInfo['hours'][5][0], 'saturday_close' => $locationInfo['hours'][5][1]]);
         if (isset($locationInfo['parent']) && !empty($locationInfo['parent'])) {
             $parent = Location::where('name', '=', $locationInfo['parent'])->first();
             if ($parent != null) {
                 $location->parent()->associate($parent);
                 $location->save();
             }
         }
         $location->saveLogo($logoImage);
         $location->saveAerialPhoto($aerialImage);
         $homePage->location()->associate($location);
         $homePage->save();
         // Generate an ID so we can attach the slider
         $homePage->slider()->save($slider);
         $navBar->location()->associate($location);
         // The old slider consisted of just these 12 images
         // The new slider consists of image/content pairs, and
         // the images are significantly wider than the old ones
         // I'm leaving this code here (commented) in case we
         // ever want to re-build the old slider. Note: I've
         // renamed the /default_images/slider/ directory to
         // /default_images/sliderOLD/
         /*
         // For all 12 slider panels, upload the image
         for( $i = 2; $i < 14; $i++ ) {
         	copy( $dirname . "/default_images/slider/" . $i . ".png", $dirname . "/Slider-" . $i . ".png" );
         	$file = new UploadedFile(
         		$dirname . "/Slider-" . $i . ".png",           // path
         		"/Slider-" . $i . ".png",                      // originalName
         		"image/png",                                   // mimeType
         		filesize($dirname . "/Slider-" . $i . ".png"), // size
         		null,                                          // error
         		true                                           // test
         	);
         	$sliderImage = ImageList::upload( $file );
         	
         	$sliderPanel = new SliderPanel();
         	$slider->panels()->save( $sliderPanel );
         	$sliderPanel->image()->save( $sliderImage );
         }
         */
         copy($dirname . "/default_images/SliderImage.jpg", $dirname . "/SliderImage.jpg");
         $file = new UploadedFile($dirname . "/SliderImage.jpg", "/SliderImage.jpg", "image/jpeg", filesize($dirname . "/SliderImage.jpg"), null, true);
         $sliderImage = ImageList::upload($file);
         $sliderPanel = new SliderPanel();
         $sliderPanel->body = "\n<h2>" . $location->name . ", " . shorten_state($location->region) . "<br />Metal Roofing</h2>\n<p>Reed's Metals is a metal roofing and pre-engineered steel building manufacturer that serves the [city], [state] area out of our " . $location->locality . " " . $location->region . " manufacturing facility.</p>\n<p>We offer a complete line of multiple metal roofing profiles in over 20 colors. Reed's Metals manufactures all of our roofing panels and buildings to meet local building codes for " . $location->locality . " " . $location->region . ".</p>\n\t\t\t";
         $slider->panels()->save($sliderPanel);
         $sliderPanel->image()->save($sliderImage);
     }
 }