Php 如何将出生日期传递到Laravel中的数据库?
我正在制作一个注册表单,其中我从用户那个里获取出生日期,但我不知道如何将它传递到数据库Php 如何将出生日期传递到Laravel中的数据库?,php,database,laravel,dob,Php,Database,Laravel,Dob,我正在制作一个注册表单,其中我从用户那个里获取出生日期,但我不知道如何将它传递到数据库 <div class="form-group row"> <label for="dob" class="col-md-4 col-form-label text-md-right"> {{ __('DOB') }}</label> <div class="col-md-6 input-group input-group-sm col-4 m-0 "> <
<div class="form-group row">
<label for="dob" class="col-md-4 col-form-label text-md-right">
{{ __('DOB') }}</label>
<div class="col-md-6 input-group input-group-sm col-4 m-0 ">
<input type="date" name="dob" style="width: 200px;" class="form-control {{
$errors->has('date') ? ' is-invalid' : '' }}" id="date" placeholder=""
required/>
@if ($errors->has('date'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('date') }}</strong>
</span>
@endif
{{{('DOB')}
@如果($errors->has('date'))
{{$errors->first('date')}
@恩迪夫
在您看来,您首先需要创建一个有效的公式,我将向您展示一个非常基本的示例,您必须自己熟练掌握这个示例
视图的外观如下所示:
在点击提交按钮后,将本例中的数据发布到该url/post/store
<form action="/post/store" method="post">
{{ csrf_field() }}
<input type="text" name="date_of_birth">
<button class="button" type="submit">
</form>
在PostController中,从公式中获取请求并创建新的帖子
class PostController extends Controller
{
public function store(Request $request)
{
Post::create([
// ... add your other data
'date_of_birth' => $request->date_of_birth
]);
return redirect()->route('/');
}
}
不要忘记在模型的可填充数组中添加新数据:
protected $fillable = [
'date_of_birth'
];
我希望你有一个适当的迁移
我建议你看一下,因为这是非常基本的东西
protected $fillable = [
'date_of_birth'
];