middleware('auth'); } /** * Function to display the moons and pass data to the blade template */ public function displayMoons() { //Setup calls to the MoonCalc class $moonCalc = new MoonCalc(); //Update the prices for the moon $moonCalc->FetchNewPrices(); //get all of the moons from the database $moons = DB::table('Moons')->orderBy('System', 'asc')->get(); //declare the html variable and set it to null $html = ''; foreach($moons as $moon) { //Setup formats as needed $spm = $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon; $rentalEnd = date('m/d/Y', $moon->RentalEnd); $price = $moonCalc->SpatialMoons($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity, $moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity); $allyPrice = $moonCalc->SpatialMoonsOutOfAlliance($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity, $moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity); //Add the data to the html string to be passed to the view $html .= ''; $html .= '' . $spm . ''; $html .= '' . $moon->StructureName . ''; $html .= '' . $moon->FirstOre . ''; $html .= '' . $moon->FirstQuantity . ''; $html .= '' . $moon->SecondOre . ''; $html .= '' . $moon->SecondQuantity . ''; $html .= '' . $moon->ThirdOre . ''; $html .= '' . $moon->ThirdQuantity . ''; $html .= '' . $moon->FourthOre . ''; $html .= '' . $moon->FourthQuantity . ''; $html .= '' . $price . ''; $html .= '' . $allyPrice . ''; $html .= '' . $moon->RentalCorp . ''; $html .= '' . $rentalEnd . ''; $html .= ''; } return view('moons.moon')->with('html', $html); } public function addMoon() { return view('moons.addmoon'); } /** * Add a new moon into the database * * @return \Illuminate\Http\Reponse */ public function storeMoon(Request $request) { $this->validate($request, [ 'region' => 'required', 'system' => 'required', 'structure' => 'required', ]); // Add new moon $moon = new Moon; $moon->Region = $request->input('region'); $moon->System = $request->input('system'); $moon->Planet = $request->input('planet'); $moon->Moon = $request->input('moon'); $moon->StructureName = $request->input('structure'); $moon->FirstOre = $request->input('firstore'); $moon->FirstQuantity = $request->input('firstquan'); $moon->SecondOre = $request->input('secondore'); $moon->SecondQuantity = $request->input('secondquan'); $moon->ThirdOre = $request->input('thirdore'); $moon->ThirdQuantity = $request->input('thirdquan'); $moon->FourthOre = $request->input('fourthore'); $moon->FourthQuantity = $request->input('fourthquan'); $moon->save(); return redirect('/dashboard')->with('success', 'Moon Added'); } public function updateMoon() { return view('moons.updatemoon'); } public function storeUpdateMoon(Request $request) { $this->validate($request, [ 'system' => 'required', 'planet' => 'required', 'moon' => 'required', 'renter' => 'required', 'date' => 'required' ]); $date = strtotime($request->date . '00:00:01'); //Update the database entry DB::table('Moons') ->where([ ['System', '=', $request->system], ['Planet', '=', $request->planet], ['Moon', '=', $request->moon] ]) ->update([ 'RentalCorp' => $request->renter, 'RentalEnd' => $date, ]); return redirect('/moons/display')->with('success', 'Moon Updated'); } }