我想在 Laravel 5.4 中使用生日年份、出生月份、出生日期作为生日的单一验证,这是我的代码
public function register(Request $request)
{
// here i want to add bithday input on reqeust but nothing happen
$request->birthday = implode('-', array(
$request->birth_year,
$request->birth_month,
$request->birth_date
));
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
return redirect()->back()->with('info', 'User successfully registered');
}
该代码没有任何反应,我可以使用 date_format 一对一地验证这些代码。问题是如果用户选择二月并且日期是 31 该怎么办
最佳答案
根据source ,您可以使用merge
方法。
$request->merge(['birthday' => implode('-', [
$request->birth_year,
$request->birth_month,
$request->birth_date
])]);
关于php - 我们可以在 laravel 中根据请求添加属性吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43344897/