public function store(StoreOptionsRequest $request) { /* Retrieve current data from database, If there is current data, then there will only be ONE row. * Otherwise, we will create a row and insert the data provided by the user. */ $opts = Options::first(); if ($opts === null) { $opts = new Options(); } /* Simply set the month and year of current issue */ $opts->current_year = Input::get('year'); $opts->current_month = Input::get('month'); if ($opts->save()) { return Redirect::to('/admin/'); } else { $years = []; /* Set years options to a range of from 5 years ago to 5 years * into the future. */ for ($i = Carbon::now()->format('Y') - 5; $i < Carbon::now()->format('Y') + 5; $i++) { $years[] = $i; } $months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; /* The current issue's month and year as retrieved from database */ $selected = ['month' => $opts->month, 'year' => $opts->year]; return View::make('admin.options', ['error' => 'Unable to save data to database!', 'options' => $opts, 'months' => $months, 'years' => $years, 'selected' => $selected]); } }