public function save_store() { $id = Input::get('id'); $white = Input::file('logo_white'); $color = Input::file('logo'); $store = Store::find($id); $cities = City::all(); $zipcodes = array(); foreach ($cities as $city) { array_push($zipcodes, $city->zipcode); } $flag = 0; if (!$store) { $store = new Store(); $flag = 1; } $store->name = Input::get('name'); $store->minimum_order_amount = Input::get('minimum_order_amount'); $validator = Validator::make(array('white' => $white, 'color' => $color), array('white' => 'required|mimes:jpeg,bmp,png', 'color' => 'required|mimes:jpeg,bmp,png')); if ($validator->fails()) { $error_messages = $validator->messages(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401); $response_code = 200; $message = "Invalid Input File"; $type = "failed"; return Redirect::to('/admin/stores')->with('type', $type)->with('message', $message); } else { if (Input::hasFile('logo')) { $store->logo_url = upload_image(Input::file('logo')); } else { if ($flag == 1) { $store->logo_url = web_url() . "/uploads/default_store_logo.png"; } } if (Input::hasFile('logo_white')) { $store->logo_white_url = upload_image(Input::file('logo_white')); } else { if ($flag == 1) { $store->logo_white_url = web_url() . "/uploads/default_white_store_logo.png"; } } $store->save(); StoreLocation::where('store_id', $id)->delete(); foreach ($zipcodes as $zipcode) { $store_location = new StoreLocation(); $store_location->store_id = $store->id; $store_location->zipcode = $zipcode; $store_location->save(); } $message = "Successfully updated the store"; $type = "success"; return Redirect::to('/admin/stores')->with('type', $type)->with('message', $message); } }