【问题标题】:How do I input custom variables in User::create() in Laravel?如何在 Laravel 的 User::create() 中输入自定义变量?
【发布时间】:2017-09-12 14:35:51
【问题描述】:
$user = User::create(request(['name', 'email', 'password']));

在上面的代码中,我需要使用什么语法来将 request()->password 变量替换为自定义的 $password 变量?

【问题讨论】:

    标签: laravel variables hash passwords


    【解决方案1】:

    最快的方法是:

    $vars = request(['name','email']);
    $vars['password'] = $password;
    $user = User::create($vars);
    

    【讨论】:

    • @SimonSuh 这是替换密码的正确方法,因为在样板模型中密码始终为hidden编辑 guarded 也不能全部填写 - 可以在 the docs regarding eloquent models 上阅读更多内容。
    猜你喜欢
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 2020-08-18
    • 2018-01-18
    • 1970-01-01
    相关资源
    最近更新 更多