对于出生日期数据的日,月和年,以及数据库中的一列dob,我有三个下拉列表。我想将所选数据转换为出生日期格式,然后存储在数据库中。这是在创建语法错误。
我的控制器代码:
protected function create(array $data)
{
'month' => $data['month'],
'day' => $data['day'],
'year' => $data['year'],
return User::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'gender' =>$data['gender'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'phone' => $data['phone'],
'dob' => "month/day/year",
]);
}
答案 0 :(得分:1)
$dob = $data['year'].'-'.$data['month'].'-'.$data['day'];
return User::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'gender' =>$data['gender'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'phone' => $data['phone'],
'dob' => $dob,
]);