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); } } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $class = Special::find($id); if ($class->delete()) { return Response::json('success', 200); } else { return Response::json('error', 400); } }
public static function getImage($special) { $special = Special::find($special); return $special->featuredImage; }
Route::get('images/{one?}/{two?}/{three?}/{four?}/{five?}', 'SiteComponents\\ImageController@loadImage'); // A few oddities Route::get('/news/{article}', function ($article) { $viewing = NewsArticle::where('slug', $article)->first(); return View::make('dynamic_pages.article')->with(['title' => $viewing->short_title, 'article' => $viewing]); }); Route::get('/locations/{location}', function ($location) { $viewing = Location::where('name', ucwords(str_replace('-', ' ', $location)))->first(); return View::make('dynamic_pages.location')->with(['title' => $viewing->name, 'viewingLocation' => $viewing]); }); Route::get('/galleries/{gallery}', function ($gallery) { $viewing = Gallery::where('slug', $gallery)->first(); return View::make('dynamic_pages.gallery')->with(['title' => $viewing->name, 'gallery' => $viewing]); }); Route::get('/specials/{special}', function ($special) { $viewing = Special::where('title', ucwords(str_replace('-', ' ', $special)))->first(); return View::make('dynamic_pages.special')->with(['title' => $viewing->title, 'special' => $viewing]); }); // Some SEO redirects Route::get('/sales-team', function () { return Redirect::to('/locations/' . strtolower(str_replace(' ', '-', Location::current()->name))); }); Route::any('/careers', function () { return Redirect::to('/resources/employment', 301); }); Route::any('/privacy', function () { return Redirect::to('/legal', 301); }); // This guy is specially generated Route::get('/sitemap.xml', function () { return Sitemap::generate();