/** * Add apartment page * @return \Illuminate\View\View */ public function home() { $apartment = new ListApartment(); //Hard code $apartment->username = Auth::user()->username; // Get all district $district = ListDistrict::lists('name_district', 'id_district'); // Get all province $province = ListProvice::lists('name_province', 'id_province'); // Get all project $projects = ListProject::lists('name', 'ID'); //Get project $project_id = Input::get('project'); $apartment->project = $project_id; // Get all furniture $furnitures = Furniture::lists('name', 'ID'); // Get all management company $directions = Direction::lists('name', 'ID'); // Get all floor material $floor_materials = FloorMaterial::lists('name', 'ID'); // Clear Session for ($i = -2; $i < 8; $i++) { if (Session::has("image[{$i}]")) { Session::remove("image[{$i}]"); } } return View::make('pages.apartment', compact('apartment', 'district', 'province', 'projects', 'project_id', 'furnitures', 'directions', 'floor_materials')); }
/** * Post project * @return \Illuminate\View\View */ public function postHome() { $inputs = Input::all(); //Remove some attribute unset($inputs['_token']); $project = new ListProject(); //Fill all value to model $project->fill($inputs); // Add new management company if (isset($inputs['management_company_new']) && $inputs['management_company_new']) { $management = new ManagementComapny(); $management->name = $inputs['management_company_new']; if ($management->save()) { $project->management_company = $management->ID; } } // Add new investor if (isset($inputs['investor_new']) && $inputs['investor_new']) { $investor = new Investor(); $investor->name = $inputs['investor_new']; if ($investor->save()) { $project->investor = $investor->ID; } } // Add new design company if (isset($inputs['design_company_new']) && $inputs['design_company_new']) { $design_company = new DesignCompany(); $design_company->name = $inputs['design_company_new']; if ($design_company->save()) { $project->design_company = $design_company->ID; } } if ($project->save()) { //Save image project for ($i = -2; $i <= -1; $i++) { if (Session::has("image[{$i}]")) { $image_arr = Session::get("image[{$i}]"); foreach ($image_arr as $image) { $image_project = new ImageProject(); $image_project->project = $project->ID; $image_project->type = $i + 2; $image_project->image = asset(sprintf('uploads/project_%s/%s', $this->_getTypeName($i), $image['image'])); $image_project->description = $image['caption']; $image_project->save(); } } } //Save image utilities $utilities = ListUtilities::all(); foreach ($utilities as $utility) { if (Session::has("image[{$utility->ID}]")) { $image_arr = Session::get("image[{$utility->ID}]"); foreach ($image_arr as $image) { $image_utility = new Utilities(); $image_utility->project = $project->ID; $image_utility->type = $utility->ID; $image_utility->image = asset(sprintf('uploads/project_%s/%s', $this->_getTypeName($utility->ID), $image['image'])); $image_utility->description = $image['caption']; $image_utility->save(); } } } } else { // Get validation errors (see Ardent package) $error = $project->validationErrors; return Redirect::back()->withErrors($error)->withInput(); } return Redirect::to('/')->with('success', "Thêm mới thành công"); }
public function getNewId() { $project = ListProject::orderBy('ID', 'desc')->first(); return $project->ID + 1; }