public function run() { DB::table('specials')->delete(); DB::table('special_details')->delete(); $specials = [['location' => 'Brookhaven', 'title' => 'Galvalume Special', 'featuredImage' => 'galvalume.jpg', 'details' => [['description' => 'Galvalume #2 only 0.99 per linear foot<br />Customer pick-up only<br />HURRY WHILE SUPPLIES LAST!<br />Order today, pick up today!', 'price_text' => 'Galvalume #2: $0.99 / ln foot', 'image' => 'galvalume2.jpg']]], ['location' => 'Brookhaven', 'title' => 'Discount Metal', 'featuredImage' => 'mocha-tan.jpg', 'details' => [['description' => '10 Year Warranty<br />29 gauge Evergreen<br />small rib / residential panel only', 'price_text' => '29 gauge: $1.79 / ln foot', 'image' => 'evergreen.jpg'], ['description' => '10 Year Warranty<br />29 gauge Polar White<br />small rib / residential panel only', 'price_text' => '29 gauge: $1.79 / ln foot', 'image' => 'polar-white.jpg'], ['description' => '10 Year Warranty<br />29 gauge Mocha Tan<br />small rib / residential panel only', 'price_text' => '29 gauge: $1.79 / ln foot', 'image' => 'mocha-tan.jpg']]]]; $dirname = dirname(__FILE__); foreach ($specials as $special) { $newSpecial = new Special(['title' => $special['title']]); $newSpecial->location()->associate(Location::where('name', $special['location'])->first()); $newSpecial->save(); copy($dirname . '/default_images/specials/' . $special['featuredImage'], $dirname . '/' . $special['featuredImage']); $file = new UploadedFile($dirname . '/' . $special['featuredImage'], $special['featuredImage'], strpos($special['featuredImage'], '.png') === false ? 'image/jpeg' : "image/png", filesize($dirname . '/' . $special['featuredImage']), null, true); $image = ImageList::upload($file); $newSpecial->featuredImage()->save($image); foreach ($special['details'] as $details) { $newDetails = new SpecialDetails(['description' => $details['description'], 'price_text' => $details['price_text']]); $newDetails->special()->associate($newSpecial); $newDetails->save(); copy($dirname . '/default_images/specials/' . $details['image'], $dirname . '/' . $details['image']); $file = new UploadedFile($dirname . '/' . $details['image'], $details['image'], strpos($details['image'], '.png') === false ? 'image/jpeg' : "image/png", filesize($dirname . '/' . $details['image']), null, true); $image = ImageList::upload($file); $newDetails->image()->save($image); } } }
public static function getImage($specialDetails) { $specialDetails = SpecialDetails::find($specialDetails); return $specialDetails->image; }