title: best practice for passing data from one Vue.js component to another in Laravel
body: <p>I have two components of Vue.js. I created two separate components for a single form in order to avoid a messy and complex code structure. I want to combine the data of these two forms in order to send it to the server. Here is my blade file which contains two components. One is StudentComponent.vue and second is TeacherComponent.vue.</p>
  <pre><code>    @extends('layouts.app')
      @section('content')
      &lt;div class=&quot;main-content&quot; id=&quot;panel&quot;&gt;
          &lt;main class=&quot;col-12 col-md-8 col-xl-7 py-md-3 pl-md-5 ct-content&quot; role=&quot;main&quot;&gt;
              &lt;div id=&quot;app&quot;&gt;
                  &lt;teacher-component :foods_array=&quot;{{ json_encode($foods) }}&quot;&gt;&lt;/teacher-component&gt;
                  &lt;student-component :foods_array=&quot;{{ json_encode($foods) }}&quot;&gt;&lt;/student-component&gt;
              &lt;/div&gt;
          &lt;/main&gt;
      &lt;/div&gt;
      @endsection
  </code></pre>
  <p>Remember that these components (StudentComponent and TeacherComponent) hierarchy does not have a parent-child component relation. My goal is to get the data from the teacher component to the student component. How can I achieve this goal?</p>
  <p>My StudentComponent.vue</p>
  <pre><code>    &lt;template&gt;
          &lt;div&gt;
              &lt;div class=&quot;card&quot; style=&quot;width: 172%;&quot;&gt;
                  &lt;!-- Form Fields --&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/template&gt;
      
      &lt;script&gt;
          export default {
              props : {
                  foods_array: {
                      type: Array,
                      required: true
                  }
              },
              beforeMount: function () {
                  this.foods = this.foods.concat(this.foods_array); 
              },
              data() {
                  return {
                      student: {
                          email: '',
                          name: '',
                          roll_number:null,
                          food: null,
                          checked: []
                      },
                      foods: [{ text: 'Select One', value: null }],
                      show: true
                  }
              },
              methods: {
                  onSubmit(evt) {
                      evt.preventDefault()
                      axios.post('api/food/store'{student:JSON.stringify(this.student),role:'student'})
                      .then(function (response) {
                          console.log(response);
                       })
                       .catch(function (error) {
                          console.log(error);
                       });
                  },
               }
          }
     &lt;/script&gt;
       
  </code></pre>
  <p>My TeacherComponent.vue</p>
  <pre><code>    &lt;template&gt;
          &lt;div&gt;
              &lt;div class=&quot;card&quot; style=&quot;width: 172%;&quot;&gt;
                  &lt;!-- Form Fields --&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/template&gt;
      
      &lt;script&gt;
          export default {
              props : {
                  foods_array: {
                      type: Array,
                      required: true
                  }
              },
              beforeMount: function () {
                  this.foods = this.foods.concat(this.foods_array); 
              },
              data() {
                  return {
                      teacher: {
                          email: '',
                          name: '',
                          department:'',
                          food: null,
                          checked: []
                      },
                      foods: [{ text: 'Select One', value: null }],
                      show: true
                  }
              },
              methods: {
                  onSubmit(evt) {
                      evt.preventDefault()
                      axios.post('api/food/store'{student:JSON.stringify(this.student),role:'teacher'})
                      .then(function (response) {
                          console.log(response);
                       })
                       .catch(function (error) {
                          console.log(error);
                       });
                  },
               }
          }
     &lt;/script&gt;
  </code></pre>