doufu7835 2017-03-11 15:57
浏览 103
已采纳

在laravel 5中从url params为模型添加值

Playing around with a referral system in laravel 5.4. I have been able to create a unique shareable link for each user.

When another user clicks on that, I want the portion of the url with the referral id of the link's original owner to be added to the referrer field of the user.

I tried this method and been getting this error, what better way is there to do this.

 use Illuminate\Support\Facades\Input;

 protected function create(array $data)
     {

    $ref = Input::get('ref');

    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
        'referrer' => $ref

    ]);

    return $user;

}

I am getting an error complaining that the referrer column cannot be null even though there is a ref on the link. Sample link.

http://localhost:8000/register?ref=1b0a6294-043d-11e7-86bf-56847afe9799

User Model

protected $fillable = [
    'name', 'email', 'password', 'level', 'btc_address', 'referrer'
];` 
  • 写回答

1条回答 默认 最新

  • dongxing4196 2017-03-11 17:11
    关注

    I think the problem might be your routes and url you use in form for registering user.

    The url you showed is probably for displaying registration form, but when you send the form, you send it to http://localhost:8000/register url so you don't have ref defined in your url.

    You should make sure, that you send form also to http://localhost:8000/register?ref=1b0a6294-043d-11e7-86bf-56847afe9799 url or put hidden field with ref value from get action.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c