public function run()
 {
     $profiles = ['Residential' => ['coverage' => 36], 'PBR' => ['coverage' => 36], 'Secure-Seam Standing Seam' => ['coverage' => 18], 'Perma-Lok Standing Seam' => ['coverage' => 16], '5-V' => ['coverage' => 24], 'Corrugated' => ['coverage' => 24], 'MECH-SEAM' => ['coverage' => 16]];
     $dirname = dirname(__FILE__);
     foreach ($profiles as $profileName => $profileInfo) {
         if (MetalProfile::where('name', '=', $profileName)->first()) {
             continue;
         }
         /*
         // Upload profile image
         copy( $dirname . "/default_images/colors/" . $colorInfo['image'], $dirname . "/" . $colorInfo['image'] );
         $file = new UploadedFile(
         	$dirname . "/" . $colorInfo['image'],             // path
         	$colorInfo['image'],                              // originalName
         	"image/png",                                      // mimeType
         	filesize( $dirname . "/" . $colorInfo['image'] ), // size
         	null,                                             // error
         	true                                              // test
         );
         $profileImage = ImageList::upload( $file );
         
         // Upload overhead image
         copy( $dirname . "/default_images/colors/" . $colorInfo['image'], $dirname . "/" . $colorInfo['image'] );
         $file = new UploadedFile(
         	$dirname . "/" . $colorInfo['image'],             // path
         	$colorInfo['image'],                              // originalName
         	"image/png",                                      // mimeType
         	filesize( $dirname . "/" . $colorInfo['image'] ), // size
         	null,                                             // error
         	true                                              // test
         );
         $overheadImage = ImageList::upload( $file );
         */
         $profile = MetalProfile::firstOrCreate(['name' => $profileName, 'coverage' => $profileInfo['coverage']]);
         $profile->save();
         foreach (Location::all() as $location) {
             foreach (Gauge::all() as $gauge) {
                 $locationProfileGauge = new LocationProfileGauge();
                 $locationProfileGauge->location()->associate($location);
                 $locationProfileGauge->metalProfile()->associate($profile);
                 $locationProfileGauge->gauge()->associate($gauge);
                 $locationProfileGauge->save();
             }
         }
     }
 }
 public function run()
 {
     $colors = ['Galvalume' => ['hex' => 'cad0d2', 'image' => 'galvalume.png'], 'Pure White' => ['hex' => 'eceaee'], 'Polar White' => ['hex' => 'f0f2f3'], 'Ivory' => ['hex' => 'f8e5c6'], 'Light Stone' => ['hex' => 'cccab2'], 'Mocha Tan' => ['hex' => 'b1946f'], 'Patina Green' => ['hex' => '6c7f56'], 'Marine Green' => ['hex' => '5b9994'], 'Forest Green' => ['hex' => '10411e'], 'Hawaiian Blue' => ['hex' => '426d7e'], 'Gallery Blue' => ['hex' => '073e60'], 'Barn Red' => ['hex' => '6e1f19'], 'Patriot Red' => ['hex' => '8c181b'], 'Burgundy' => ['hex' => '512127'], 'Cocoa Brown' => ['hex' => '513d30'], 'Metallic Copper' => ['hex' => 'b15726'], 'Galvanized Silver' => ['hex' => 'afafb1', 'image' => 'galvanized_silver.png'], 'Old Town Gray' => ['hex' => '898b8e'], 'Clay' => ['hex' => '979888'], 'Charcoal Gray' => ['hex' => '565656'], 'Burnished Slate' => ['hex' => '342019'], 'Black' => ['hex' => '030303'], 'Ash Gray' => ['hex' => 'aca1a1'], 'Evergreen' => ['hex' => '394f46']];
     $dirname = dirname(__FILE__);
     foreach ($colors as $colorName => $colorInfo) {
         if (Color::where('name', '=', $colorName)->first()) {
             continue;
         }
         if (empty($colorInfo['hex'])) {
             // Nothing we can do (yet)
             continue;
         }
         // Upload image, if exists
         $colorImage = null;
         if (isset($colorInfo['image'])) {
             copy($dirname . "/default_images/colors/" . $colorInfo['image'], $dirname . "/" . $colorInfo['image']);
             $file = new UploadedFile($dirname . "/" . $colorInfo['image'], $colorInfo['image'], "image/png", filesize($dirname . "/" . $colorInfo['image']), null, true);
             $colorImage = ImageList::upload($file);
         }
         $redHex = substr($colorInfo['hex'], 0, 2);
         $greenHex = substr($colorInfo['hex'], 2, 2);
         $blueHex = substr($colorInfo['hex'], 4, 2);
         $color = Color::firstOrCreate(['name' => $colorName, 'red' => hexdec($redHex), 'green' => hexdec($greenHex), 'blue' => hexdec($blueHex)]);
         $color->save();
         if ($colorImage != null) {
             $color->image()->save($colorImage);
         }
         foreach (Location::all() as $location) {
             foreach (Gauge::all() as $gauge) {
                 $locationColorGauge = new LocationColorGauge();
                 $locationColorGauge->location()->associate($location);
                 $locationColorGauge->color()->associate($color);
                 $locationColorGauge->gauge()->associate($gauge);
                 $locationColorGauge->save();
             }
         }
     }
 }
 public function detach()
 {
     $location = Location::find(Request::input('location'));
     $profile = MetalProfile::find(Request::input('profile'));
     foreach (Gauge::all() as $gauge) {
         $locationProfileGauge = LocationProfileGauge::where('location_id', '=', $location->id)->where('metal_profile_id', '=', $profile->id)->where('gauge_id', '=', $gauge->id);
         if ($locationProfileGauge->first()) {
             $locationProfileGauge->first()->delete();
         }
     }
     return "success";
 }
 public function detach()
 {
     $location = Location::find(Request::input('location'));
     $color = Color::find(Request::input('color'));
     foreach (Gauge::all() as $gauge) {
         $locationColorGauge = LocationColorGauge::where('location_id', '=', $location->id)->where('color_id', '=', $color->id)->where('gauge_id', '=', $gauge->id);
         if ($locationColorGauge->first()) {
             $locationColorGauge->first()->delete();
         }
     }
     return "success";
 }