php - 我们可以在 laravel 中根据请求添加属性吗

标签 php laravel laravel-5.3

我想在 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/

相关文章:

php - 有没有办法使用 jquery .ready 函数获取 Joomla 模块位置和功能?

php - 使用 PHP 从 html 标签中删除属性,同时保留特定属性

php - 带有 socket-io 的 Laravel 事件 [接收通知]

php - 如何在 Laravel 中使用相同的 Blade 模板对一个 Controller 进行添加和编辑操作?

model - 在 laravel 5.3 中使用 Eloquent 连接两个模型

php - 如何提高 MySQL 数据库的性能

php - 无法打开流权限被拒绝

php - 无法访问 Laravel 中的存储文件夹

laravel - 加载资源失败:net::ERR_CONTENT_DECODING_FAILED 错误,同时加载 laravel css 文件

laravel - 设置 Laravel Flash 消息的时间间隔