public function joinQueue() { $user = Auth::user(); if ($user->waitingPosition != null || $user->canStartGardening != null) { session()->flash('errorMessages', ['You can\'t join the queue because you\'re already in the queue or you can start gardening.']); return back(); } $user->waitingPosition = Carbon::now(); $user->save(); // if there are no people in front on the waiting list and there is a plantPlot free, send and email and set canStartGardening to now $plantPlots = PlantPlot::getEmptyPlots(); $usersThatCanStartGardening = User::getUsersThatCanStartGardening(); if (count($plantPlots) != 0 && count($plantPlots) > count($usersThatCanStartGardening)) { // get user first on waiting list $firstUserInLine = User::getFirstUserInWaitingList(); if ($user->id == $firstUserInLine->id) { // user can start gardening from this point and is removed from waiting list $user->canStartGardening = Carbon::now(); $user->waitingPosition = null; $user->save(); // send email to user // // session()->flash('successMessage', 'Congratulations, you were first in queue so you can start gardening right away!'); return back(); } } session()->flash('successMessage', 'Congratulations, you\'re in the queue!'); return back(); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('plantPlots')->delete(); PlantPlot::create(['pin' => 2, 'isHarvested' => false, 'isPlanted' => false]); PlantPlot::create(['pin' => 3, 'isHarvested' => false, 'isPlanted' => false]); PlantPlot::create(['pin' => 4, 'isHarvested' => false, 'isPlanted' => false]); PlantPlot::create(['pin' => 17, 'isHarvested' => false, 'isPlanted' => false]); }
public function receiveMoist(Request $request) { $all = $request->all(); $plantPlots = PlantPlot::all(); foreach ($plantPlots as $plantPlot) { if (count($plantPlot->plant)) { $moisture = new Moisture(); $moisture->date = Carbon::now(); $moisture->value = $request->get($plantPlot->pin); $plantPlot->plant->moisture()->save($moisture); } } return $all; }
public function removePlant($id) { $plantPlot = PlantPlot::findOrFail($id); $plant = $plantPlot->plant; // send mail to user plant has been removed // // // reset plant $plantPlot->plant_id = 0; $plantPlot->isHarvested = 0; $plantPlot->isPlanted = 0; $plantPlot->save(); session()->flash('successMessage', 'You have removed the plant from plot ' . $plantPlot->id); return 'remove plant ' . $id . ' ' . $plantPlot->plant->plantCharacter->name . ' ' . $plantPlot->plant->plantSpecies->name; }
public function getEmptyPlotForReuse() { return PlantPlot::where('isHarvested', true)->where('isPlanted', false)->first(); }