public function postStartGardening(StartGardeningRequest $request) { $user = Auth::user(); // if canStartGardening + 2 days < now => redirect if ($user->canStartGardening->addDays(2) < Carbon::now()) { session()->flash('errorMessages', ['Sorry but your time to start gardening has expired.']); return redirect()->route('dashboard'); } // update the user with the shipping address and paymnent info and set canStartGardening to null $request->merge(array('canStartGardening' => null)); $user->update($request->only('street', 'streetnumber', 'city', 'postalcode', 'country', 'payment_method', 'card_number', 'cvc', 'canStartGardening')); // create the new plant and attach it to the plantPlot $plant = new Plant(); $plant->plantCharacter_id = $request->get('plant_character'); $plant->plantSpecies_id = $request->get('plant_species'); $plant->isPremium = $request->get('tier') == 'premium' ? true : false; $plant->save(); // find an empty plantPlot and fill it with the new plant $plantPlot = PlantPlot::getEmptyPlot(); $plantPlot->isPlanted = true; $plantPlot->plant_id = $plantPlot->id; // attach the plant to the plantPlot $plantPlot->save(); // attach the plant to the user $user->plants()->attach($plant, ['isOwner' => true, 'hasAccepted' => true]); $plantSpecies = PlantSpecies::findOrFail($request->get('plant_species')); // flash success message $request->session()->flash('successMessages', ['Congratulations! It\'s a ' . $plantSpecies->name . '.']); return redirect()->route('dashboard'); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('plantSpecies')->delete(); PlantSpecies::create(['name' => 'radish']); PlantSpecies::create(['name' => 'spinach']); PlantSpecies::create(['name' => 'broccoli']); PlantSpecies::create(['name' => 'beetroot']); }