title: How do I make a referral program in Laravel?
body: <p>I am trying to create a program where other users can sign up using links of other already registered users. So, when one is referred, this is how the url would look like</p>
  
  <pre><code>mywebsite.com/register?ref_id=555 // ref_id is existing user id
  </code></pre>
  
  <p>I am using the default Laravel auth. There is a hidden input value which would contain the value of <code>ref_id</code> if it exists. My database has a column called <code>referred_by</code> which is an <code>INT</code>and set to <code>null</code> by default. When someone registers using the link with ref_id, that id will get saved into that user row. 
  But the problem is it's getting saved as null everytime. </p>
  
  <p>This is how the validator looks like in <code>Auth/RegisterController.php</code> </p>
  
  <pre><code>protected function validator(array $data)
  {
      return Validator::make($data, [
          'first_name' =&gt; 'required|max:40',
          'last_name' =&gt; 'required|max:40',
          'email' =&gt; 'required|email|max:255|unique:users',
          'account_name' =&gt; 'required|max:80',
          'account_number'=&gt; 'required|max:15',
          'bank_name'=&gt; 'required|max:30',
          'phone_number' =&gt; 'required|max:15',
          'ref_id' =&gt; 'nullable|numeric',
          'username' =&gt; 'required|max:15|unique:users',
          'password' =&gt; 'required|min:6|confirmed',
      ]);
  }
  </code></pre>
  
  <p>and this is how the create method look like</p>
  
  <pre><code>protected function create(array $data)
  {
      return User::create([
          'first_name' =&gt; $data['first_name'],
          'last_name' =&gt; $data['last_name'],
          'email' =&gt; $data['email'],
          'account_name'=&gt; $data['account_name'],
          'account_number' =&gt; $data['account_number'],
          'bank_name'=&gt; $data['bank_name'],
          'phone_number'=&gt; $data['phone_number'],
          'username' =&gt; $data['username'],
          'referred_id' =&gt; (int)$data['ref_id'],
          'password' =&gt; bcrypt($data['password']),
      ]);
  }
  </code></pre>
  
  <p>Since ref_id is saved in the hidden input field as a string, I tried converting it into an integer before putting into the database but I am not able to get it to work.
  I am really confused on how I can achieve this. 
  Please help me.
  Thanks in advance. </p>