Php 如何在laravel中的my函数中获取出生日期参数?

Php 如何在laravel中的my函数中获取出生日期参数?,php,laravel,laravel-5,database-design,Php,Laravel,Laravel 5,Database Design,我的视图代码是 <div class="form-group {!! $errors->has('date_of_birth') ? 'has-error' : '' !!}"> {!! Form::label('date_of_birth', 'Date of Birth', ['class' => 'control-label']) !!} <div class="form-inline"> {!! Form::selectRange('date_of_b

我的视图代码是

<div class="form-group {!! $errors->has('date_of_birth') ? 'has-error' : '' !!}">
{!! Form::label('date_of_birth', 'Date of Birth', ['class' => 'control-label']) !!}
<div class="form-inline">
{!! Form::selectRange('date_of_birth[day]', 1, 31, null, ['class' => 'selectbody fl']) !!}
{!! Form::selectMonth('date_of_birth[month]', null, ['class' => 'selectbody fl']) !!}
{!! Form::selectYear('date_of_birth[year]', date('Y') - 3, date('Y') - 40, null, ['class' => 'selectbody fl']) !!}
</div>
{!! $errors->first('date_of_birth', '<span class="help-block">:message</span>') !!}
</div>
    $data= array(
     "mybirthday"=>$date_of_birth,
    );
定义要保存DOB的列

<div class="form-group {!! $errors->has('date_of_birth') ? 'has-error' : '' !!}">
{!! Form::label('date_of_birth', 'Date of Birth', ['class' => 'control-label']) !!}
<div class="form-inline">
{!! Form::selectRange('date_of_birth[day]', 1, 31, null, ['class' => 'selectbody fl']) !!}
{!! Form::selectMonth('date_of_birth[month]', null, ['class' => 'selectbody fl']) !!}
{!! Form::selectYear('date_of_birth[year]', date('Y') - 3, date('Y') - 40, null, ['class' => 'selectbody fl']) !!}
</div>
{!! $errors->first('date_of_birth', '<span class="help-block">:message</span>') !!}
</div>
    $data= array(
     "mybirthday"=>$date_of_birth,
    );
保存在数据库中

    if(DB::table('userspathik')->insert($data))
    {
    return redirect('signup')->with("success","You are registered");
    }

你应该更清楚这个问题。所以我的理解是,你有单独的列为日,月和年。提交表单时,希望将这些字段保存在数据库中的单个“datetime”列中

我不知道你用的是什么版本,但我希望它是最新的

我建议您使用单个日期输入字段,并使用
strotime
Carbon
对其进行解析,这样您就可以使用laravel验证方法对其进行验证,如
日期、日期格式、日期之前、日期之后等。以下是示例:

public function signMeUp(Request $request)
{
    $validatedInput = $request->validate([
       'dob' => 'required|date|date_format:"d/m/Y"'
    ]);

    $dob = $validatedInput['dob'];

    # Parse the date according to format
    $dob = \Carbon\Carbon::createFromFormat('d/m/Y', $dob);

    # Replace with your required model
    $model = new $model();
    $model->$dob;
    $model->save();

    return redirect('/register')->with('status', 'Registration Successful');

}
如果您想使用单独的输入字段,如日、月和年,您可以将这些字段组合起来,如

$dob = $request->get('dob_day').'/'.$request->get('dob_month').'/'.$request->get('dob_year');
不过,您需要单独验证它。
你明白了…

问题是什么?你卡在哪里了?代码似乎很好,你的目标是什么problem@Hussein我想问datetime是否适合存储出生日期?@HasanTıngır如何在我的函数中获取这些参数..请参阅更新的代码。谢谢您先格式化代码,我发现您上面的模式函数代码中缺少了结束括号,也缺少了表单结束标记,我建议您从laravel文档开始,它更清晰、简洁、简单。