0

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'
];` 
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291

1 Answers1

1

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.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291