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]);
     }
 }
Esempio n. 2
0
 public function index()
 {
     $options = Options::first();
     //dd($options);
     $issue = Issues::where('year', $options->current_year)->where('month', $options->current_month)->first();
     //dd($issue);
     return View::make('index', ['issue' => $issue]);
 }
Esempio n. 3
0
 public function index()
 {
     $options = Options::first();
     //dd($options);
     $current = Issues::where('year', $options->current_year)->where('month', $options->current_month)->first();
     //dd($current);
     $issues = Issues::all();
     return View::make('issues', ['current' => $current, 'issues' => $issues, 'months' => Config::get('months')]);
 }
 public function create()
 {
     $opts = Options::first();
     /* Set years options to a range of from 5 years ago to 5 years
      * into the future.
      */
     $years = [];
     for ($i = Carbon::now()->format('Y') - 5; $i < Carbon::now()->format('Y') + 5; $i++) {
         $years[] = $i;
     }
     return View::make('admin.issues.add', ['error' => 'none', 'year' => Carbon::now()->format('Y'), 'months' => Config::get('months')]);
 }