title: How to i insert foreign key to my database table
body: <p>I have two table having relationship but when I do send data into database I got <code>NULL</code>, I am using Vuejs with Laravel normally in laravel I may use foreach loop to do so but I am a beginner with laravel &amp; Vuejs</p>
  
  <p>My two tables are students and parent, I have a foreign key at student table that references parent id </p>
  
  <p>Anyone one who can help me how go through this</p>
  
  <p>My problem is when i send data the foreign key at student table is inserted as NULL</p>
  
  <p>This is my student model:</p>
  
  <pre><code>protected $fillable = [
      'pregistration_id',
      'admission_no',
      'fname',
      'mname',
      'lname',
      'dob',
      'gender',
      'primary_school',
      'form_enrolled',
      'transfered_from',
      'transfered_to',
  ];
  </code></pre>
  
  <p>This is my parent model:</p>
  
  <pre><code>protected $fillable = [
      'fname',
      'mname',
      'lname',
      'residence',
      'phone',
      'occupation',
  ];
  </code></pre>
  
  <p>This is my student controller:</p>
  
  <pre><code>return Student::create([
      'pregistration_id'=&gt;$request['pregistration_id'],
      'admission_no'=&gt;$request['admission_no'],
      'fname'=&gt;$request['fname'],
      'mname'=&gt;$request['mname'],
      'lname'=&gt;$request['lname'],
      'dob'=&gt;$request['dob'],
      'gender'=&gt;$request['gender'],
      'primary_school'=&gt;$request['primary_school'],
      'form_enrolled'=&gt;$request['form_enrolled'],
      'transfered_from'=&gt;$request['transfered_from'],
      'transfered_to'=&gt;$request['transfered_to'],
      // dd($request-&gt;all())
  ]);
  </code></pre>
  
  <p>This is my students table:</p>
  
  <pre><code>Schema::create('students', function (Blueprint $table) {
      $table-&gt;bigIncrements('id');
      $table-&gt;bigInteger('pregistration_id')-&gt;unsigned()-&gt;nullable();
      $table-&gt;integer('admission_no')-&gt;unique();
      $table-&gt;string('fname');
      $table-&gt;string('mname');
      $table-&gt;string('lname');
      $table-&gt;date('dob');
      $table-&gt;string('gender');
      $table-&gt;string('primary_school');
      $table-&gt;string('form_enrolled');
      $table-&gt;string('transfered_from');
      $table-&gt;string('transfered_to');
      $table-&gt;foreign('pregistration_id')-&gt;references('id')-&gt;on('pregistrations');
      $table-&gt;timestamps();
  });
  </code></pre>
  
  <p>This is a part of student component in Vue:</p>
  
  <pre><code>data() {
    return {
      editmode: false,
      students: {},
      form: new Form({
        id: '',
        admission_no: '',
        fname: '',
        mname: '',
        lname: '',
        dob: '',
        gender: '',
        primary_school: '',
        form_enrolled: '',
        trasfered_from:'',
        trasfered_to: ''
      })
    }
  },
  </code></pre>