title: How to read URL parameters in laravel
body: <p>I am begginer, and trying to create a referral system. following is sample url</p>
  
  <pre><code>http://dev.lea.com/register?ref=mh2HPLpVSn
  </code></pre>
  
  <p>I try to get referral string. how can i get separately? is there need of middleware for getting cookies? if yes then what will be code of middleware? and how can i get referral reference in RegisterController?</p>
  
  <p>Here is my Register Controller.</p>
  
  <pre><code>&lt;?php
  
  namespace Lea\Http\Controllers\Auth;
  
  use DB;
  use Lea\User;
  use Lea\Http\Controllers\Controller;
  use Illuminate\Support\Facades\Validator;
  use Illuminate\Foundation\Auth\RegistersUsers;
  use Illuminate\Http\Request;
  use Cookie;
  
  class RegisterController extends Controller
  {
      /*
      |--------------------------------------------------------------------------
      | Register Controller
      |--------------------------------------------------------------------------
      |
      | This controller handles the registration of new users as well as their
      | validation and creation. By default this controller uses a trait to
      | provide this functionality without requiring any additional code.
      |
      */
  
      use RegistersUsers;
  
      /**
       * Where to redirect users after registration.
       *
       * @var string
       */
      protected $redirectTo = '/';
  
      /**
       * Create a new controller instance.
       *
       * @return void
       */
      public function __construct()
      {
          $this-&gt;middleware('guest');
      }
  
      /**
       * Get a validator for an incoming registration request.
       *
       * @param  array  $data
       * @return \Illuminate\Contracts\Validation\Validator
       */
  
      protected function validator(array $data)
      {
          return Validator::make($data, [
              'fname' =&gt; 'required|string|max:255',
              'lname' =&gt; 'required|string|max:255',
              'referral' =&gt; 'string|max:255',
              'username' =&gt; 'required|string|max:255',
              'email' =&gt; 'required|string|email|max:255|unique:users',
              'password' =&gt; 'required|string|min:6|confirmed',
              // 'tracking_id' =&gt; 'required',
          ]);
      }
  
      /**
       * Create a new user instance after a valid registration.
       *
       * @param  array  $data
       * @return \Lea\User
       */
      protected function create(array $data, Request $request)
      {
  
          //  printing here referral Link
          echo $request()-&gt;ref;
  
  
          // $referred_by = Cookie::get();
          // print_r($referred_by); 
          die;
  
          return User::create([
              'fname' =&gt; $data['fname'],
              'lname' =&gt; $data['lname'],
              'username' =&gt; $data['username'],
              'email' =&gt; $data['email'],
              'password' =&gt; bcrypt($data['password']),
              'affiliate_id' =&gt; str_random(10),
              // 'referred_by' =&gt; $referred_by,
              'identity' =&gt; $data['identity'],
              'dob' =&gt; $data['dob'],
              'board_id' =&gt; $data['board_id'],
              'class_id' =&gt; $data['class_id'],
              'subject_id' =&gt; $data['subject_id'],
              'institute' =&gt; $data['institute'],
              'address' =&gt; $data['address'],
              'city' =&gt; $data['city'],
              'std_mobile' =&gt; $data['std_mobile'],
              'father_name' =&gt; $data['father_name'],
              'father_mobile' =&gt; $data['father_mob'],
              'ipadress' =&gt; \Request::ip(),
          ]);
      }
  
  }
  </code></pre>