title: Storing data to multiple tables from single form in laravel
body: <p>My schemas are: </p>
  
  <pre><code>Schema::create('persons', function (Blueprint $table) {
          $table-&gt;bigInteger('university_id')-&gt;unique()-&gt;unsigned();
          $table-&gt;string('category');
          $table-&gt;string('name');
          $table-&gt;timestamps();
    });
  
  Schema::create('teachers', function (Blueprint $table) {
          $table-&gt;increments('teacher_id');
          $table-&gt;bigInteger('university_id')-&gt;unsigned();
          $table-&gt;string('position');
          $table-&gt;string('courses');
          $table-&gt;integer('salary');
          $table-&gt;timestamps();
    });
  
  Schema::create('students', function (Blueprint $table) {
          $table-&gt;increments('student_id');
          $table-&gt;bigInteger('university_id')-&gt;unsigned();
          $table-&gt;string('year');
          $table-&gt;string('semester');
          $table-&gt;string('programme');
          $table-&gt;integer('rollNum');
          $table-&gt;timestamps();
    });
  </code></pre>
  
  <p>I have a two forms with fields:</p>
  
  <ul>
  <li><strong>For Teachers</strong>:University ID, Name, Category, Position, Courses, Salary</li>
  <li><strong>For Students</strong>:University ID, Name, Category, Year, Semester, Programme, Roll Number</li>
  </ul>
  
  <p>I tried to store data in the database through my controller in single method as follows:
  After requesting all data into variables from form, I tried to store data in the following way.</p>
  
  <pre><code>University::create([
       'university_id' =&gt;$universityID,
       'category' =&gt; $category,
       'name' =&gt; $name
   ]);
  
  //I passed values of category as Teacher when submitting from teacher form 
  //and Student while submitting student form.
  
  if($category == 'Teacher'){
    Teacher::create([
      'university_id' =&gt; $universityID,
      'position' =&gt; $position,
      'courses' =&gt; $course,
      'salary' =&gt; $salary
    ]);
  }
  
    if($category == 'Student'){
       Student::create([
         'university_id' =&gt; $universityID,
         'year' =&gt; $year,
         'semester' =&gt; $semester,
         'programme' =&gt; $programme,
         'rollNum' =&gt; $roll
       ]);
  }
  </code></pre>
  
  <p>When i submitted Teacher's form, I was expecting that data will be stored in University and Teachers table only and it did. But there was an unexpected problem occurred. The Student table was filled with Null values. I was expecting if condition will prevent running <code>Student::create([])</code> 
  So how can I store values only in University and Teachers table when submitting from teachers form and University and Students table only when submitting from students form without having null values in either of them.</p>