sql - Implode separate date of birth values from php form -
ok i'm out of ideas , have reached end point in research.
have registration form birthdate select fields example below:
<div class="row"> <div class="col-xs-2"> {!! form::selectmonth('dob_month', 1, ['class'=> 'form-control']) !!} </div> <div class="col-xs-2"> {!! form::selectrange('dob_date', 1, 31, 1, ['class'=> 'form-control']) !!} </div> <div class="col-xs-2"> {!! form::selectyear('dob_year', 1930, 1997, 1991, ['class'=> 'form-control']) !!} </div> </div> of course in laravel's blade template.
as can see 3 separate select forms dob_month, dob_date , dob_year , values onto mutator thats in user model
private function setdobattribute($dob){ $dobstring = ['dob_year', 'dob_month', 'dob_date']; $this->attributes['dob'] = implode('-', array_values($dobstring)); } with dob sql column name.
the issue
i want capture dob_year, dob_month, dob_date structured 1997-12-01 using implode('-'array_values($dobstring)) saved database.
when go through process of signing new user error message of undefined index: dob.
now getting feeling in mutator function setdobattribute($dob) missing within function code can't seem put finger on is.
input? suggestions?
thank in advance.
use array_map may be...
private function setdobattribute($dob){ $keys = ['dob_year', 'dob_month', 'dob_date']; $this->attributes['dob'] = implode('-', array_map(function($key) use($dob){ return $dob[$key]; }, $keys)); return $this; }
Comments
Post a Comment