如何从多个下拉列表中选择数据并将它们组合成laravel中的一个变量?

时间:2018-06-11 11:26:18

标签: laravel-5 laravel-5.5

对于出生日期数据的日,月和年,以及数据库中的一列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",
    ]);
}

1 个答案:

答案 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,
    ]);