Skip to content

Instantly share code, notes, and snippets.

@Jhhames
Last active February 17, 2019 23:35
Show Gist options
  • Save Jhhames/e04a0cf1e2e64aa477ddeb10d63f091b to your computer and use it in GitHub Desktop.
Save Jhhames/e04a0cf1e2e64aa477ddeb10d63f091b to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $thisYear;
public function __construct(){
$this->thisYear = $this->getYear();
}
function submitForm(Request $request){
$year = $request->year;
echo $year;
if($year >= $this->thisYear || $year <= 1900 ){
Session::flash('error','Invalid year, year must be less than 2020 or greater than 1900');
return redirect()->back();
}else{
$age = $this->thisYear - $year;
Session::flash('success','You\'re ' .$age. ' years old');
return redirect()->back();
}
}
protected function getYear(){
return (int)Date('Y');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment