Reputation: 521
This is what I have, it is just storing the values multiple times even though I have a rules to check the uniqueness against "appointments" table in the database. Can anyone suggest me how I can store only unique date in my table. Thanks in advance.
public function store()
{
date_default_timezone_set('Australia/Melbourne');
$date = date('Y/m/d', time());
$todDate = new DateTime($date);
$dateFormated = $todDate->format('Y-m-d');
$input = Input::all();
$rules = array(
'appoint_day' => 'required|unique:appointments'
);
$validator = Validator::make($input, $rules);
if($validator->passes())
{
$schedule = new Appointment;
$appoint_day = Input::get('appoint_date');
if(strtotime($appoint_day) - strtotime($dateFormated) >= 0)
{
$schedule->user_id = Auth::user()->id;
$schedule->appoint_day = $appoint_day;
$schedule->save();
}
}
else
{
echo 'failed';
}
return View::make('admin.professions.appointments');
}
Upvotes: 0
Views: 1046
Reputation: 7381
Your Input
value is named appoint_date
, but you are validating a field called appoint_day
, which presumably does not exist. Change your field name to appoint_day
and the validator should function correctly.
Upvotes: 1