我想在数据库的1列中保存3个输入
$register = $request->validate([
'year' => 'required|numeric|min:1320|max:1398',
'month' => 'required|numeric|min:1|max:12',
'date' => 'required|numeric|min:1|max:31',]);
$user=user_information::where('user_id',$id)->first();
$user->birthday = $request->input('year');
$user->birthday = $request->input('month');
$user->birthday = $request->input('date');
或
$user->birthday = $request->input('year'.'-'.'month'.'-'.'date');
答案 0 :(得分:0)
您需要合并输入。
$user->birthday = $request->input('date') . '-' .
$request->input('month') . '-' .
$request->input('year');
答案 1 :(得分:0)
在这种情况下,您可以使用Carbon
:
$user->birthday = \Carbon\Carbon::create()->setDate(
$request->input('year'),
$request->input('month'),
$request->input('day')
);
只需确保在用户模型中将birthday
强制转换为日期:
protected $casts = [
// other casts
'birthday' => 'date',
];