How to create private channel name dynamically












0















I woluld like to create real-time order tracking system using laravel, vue and pusher. In admin panel I have list of all orders. The idea is when admin change order status the user (owner of this order) will get notification without refreshing page. To make it I want to use private channels. My problem is to create private channel name dynamically.



Admin panel looks like below.



<h1>Admin</h1>
<table>
@foreach ($orders as $o)
<tr>
<td>{{$o->name}}</td>
<td>{{$o->status}}</td>
<td>{{$o->getUser->name}}</td>
<td>
<update-order-status :id="{{$o->id}}"></update-order-status>
</td>
</tr>
@endforeach
</table>


There is update-order-status component which is a form used to change status of order. Id of order is passed to component via props. Content of component look like below:



///update-order-status component
<template>
<div>
<form method="GET" action="change_status">
<input type="hidden" name="id" :value=id />
<select name="status">
<option value="placed">Placed</option>
<option value="progres">Progres</option>
<option value="delivered">Delivered</option>
</select>
<input type="submit" value="update status" v-on:click="upd(id)" />
</form>
</div>
</template>

<script>
export default {
created() {
},
props: ["id"],

data: function() {
return {


};
},

methods: {
upd: function(id) {
this.$root.$emit("eve", id);
}
}
};
</script>


When admin submit form order status is updated in database and also event eve is emitted. This event is used to pass id of order to status-changed compoennt. This component is placed in user panel and contains notification that order status has been changed.



///status changed component

<template>
<div v-if="sn" class="notification is-primary">
<button class="delete" v-on:click="del()"></button>
Staus of order nr {{nr}} has been changed
</div>
</template>

<script>
export default {
created() {
this.$root.$on("eve", data => {
this.nr = data;
});
Echo.private("order" + this.nr).listen("status_changed", e => {
this.sn = true;
});
},
props: ,

data: function() {
return {
sn: false,
nr: 0
};
},
methods: {
del: function() {
this.sn = false;
}
}
};
</script>


Here is the problem. Variable nr is 0 all time. It'not changing dynamically. When nr is static or channel is public this code works fine. Please help.










share|improve this question



























    0















    I woluld like to create real-time order tracking system using laravel, vue and pusher. In admin panel I have list of all orders. The idea is when admin change order status the user (owner of this order) will get notification without refreshing page. To make it I want to use private channels. My problem is to create private channel name dynamically.



    Admin panel looks like below.



    <h1>Admin</h1>
    <table>
    @foreach ($orders as $o)
    <tr>
    <td>{{$o->name}}</td>
    <td>{{$o->status}}</td>
    <td>{{$o->getUser->name}}</td>
    <td>
    <update-order-status :id="{{$o->id}}"></update-order-status>
    </td>
    </tr>
    @endforeach
    </table>


    There is update-order-status component which is a form used to change status of order. Id of order is passed to component via props. Content of component look like below:



    ///update-order-status component
    <template>
    <div>
    <form method="GET" action="change_status">
    <input type="hidden" name="id" :value=id />
    <select name="status">
    <option value="placed">Placed</option>
    <option value="progres">Progres</option>
    <option value="delivered">Delivered</option>
    </select>
    <input type="submit" value="update status" v-on:click="upd(id)" />
    </form>
    </div>
    </template>

    <script>
    export default {
    created() {
    },
    props: ["id"],

    data: function() {
    return {


    };
    },

    methods: {
    upd: function(id) {
    this.$root.$emit("eve", id);
    }
    }
    };
    </script>


    When admin submit form order status is updated in database and also event eve is emitted. This event is used to pass id of order to status-changed compoennt. This component is placed in user panel and contains notification that order status has been changed.



    ///status changed component

    <template>
    <div v-if="sn" class="notification is-primary">
    <button class="delete" v-on:click="del()"></button>
    Staus of order nr {{nr}} has been changed
    </div>
    </template>

    <script>
    export default {
    created() {
    this.$root.$on("eve", data => {
    this.nr = data;
    });
    Echo.private("order" + this.nr).listen("status_changed", e => {
    this.sn = true;
    });
    },
    props: ,

    data: function() {
    return {
    sn: false,
    nr: 0
    };
    },
    methods: {
    del: function() {
    this.sn = false;
    }
    }
    };
    </script>


    Here is the problem. Variable nr is 0 all time. It'not changing dynamically. When nr is static or channel is public this code works fine. Please help.










    share|improve this question

























      0












      0








      0








      I woluld like to create real-time order tracking system using laravel, vue and pusher. In admin panel I have list of all orders. The idea is when admin change order status the user (owner of this order) will get notification without refreshing page. To make it I want to use private channels. My problem is to create private channel name dynamically.



      Admin panel looks like below.



      <h1>Admin</h1>
      <table>
      @foreach ($orders as $o)
      <tr>
      <td>{{$o->name}}</td>
      <td>{{$o->status}}</td>
      <td>{{$o->getUser->name}}</td>
      <td>
      <update-order-status :id="{{$o->id}}"></update-order-status>
      </td>
      </tr>
      @endforeach
      </table>


      There is update-order-status component which is a form used to change status of order. Id of order is passed to component via props. Content of component look like below:



      ///update-order-status component
      <template>
      <div>
      <form method="GET" action="change_status">
      <input type="hidden" name="id" :value=id />
      <select name="status">
      <option value="placed">Placed</option>
      <option value="progres">Progres</option>
      <option value="delivered">Delivered</option>
      </select>
      <input type="submit" value="update status" v-on:click="upd(id)" />
      </form>
      </div>
      </template>

      <script>
      export default {
      created() {
      },
      props: ["id"],

      data: function() {
      return {


      };
      },

      methods: {
      upd: function(id) {
      this.$root.$emit("eve", id);
      }
      }
      };
      </script>


      When admin submit form order status is updated in database and also event eve is emitted. This event is used to pass id of order to status-changed compoennt. This component is placed in user panel and contains notification that order status has been changed.



      ///status changed component

      <template>
      <div v-if="sn" class="notification is-primary">
      <button class="delete" v-on:click="del()"></button>
      Staus of order nr {{nr}} has been changed
      </div>
      </template>

      <script>
      export default {
      created() {
      this.$root.$on("eve", data => {
      this.nr = data;
      });
      Echo.private("order" + this.nr).listen("status_changed", e => {
      this.sn = true;
      });
      },
      props: ,

      data: function() {
      return {
      sn: false,
      nr: 0
      };
      },
      methods: {
      del: function() {
      this.sn = false;
      }
      }
      };
      </script>


      Here is the problem. Variable nr is 0 all time. It'not changing dynamically. When nr is static or channel is public this code works fine. Please help.










      share|improve this question














      I woluld like to create real-time order tracking system using laravel, vue and pusher. In admin panel I have list of all orders. The idea is when admin change order status the user (owner of this order) will get notification without refreshing page. To make it I want to use private channels. My problem is to create private channel name dynamically.



      Admin panel looks like below.



      <h1>Admin</h1>
      <table>
      @foreach ($orders as $o)
      <tr>
      <td>{{$o->name}}</td>
      <td>{{$o->status}}</td>
      <td>{{$o->getUser->name}}</td>
      <td>
      <update-order-status :id="{{$o->id}}"></update-order-status>
      </td>
      </tr>
      @endforeach
      </table>


      There is update-order-status component which is a form used to change status of order. Id of order is passed to component via props. Content of component look like below:



      ///update-order-status component
      <template>
      <div>
      <form method="GET" action="change_status">
      <input type="hidden" name="id" :value=id />
      <select name="status">
      <option value="placed">Placed</option>
      <option value="progres">Progres</option>
      <option value="delivered">Delivered</option>
      </select>
      <input type="submit" value="update status" v-on:click="upd(id)" />
      </form>
      </div>
      </template>

      <script>
      export default {
      created() {
      },
      props: ["id"],

      data: function() {
      return {


      };
      },

      methods: {
      upd: function(id) {
      this.$root.$emit("eve", id);
      }
      }
      };
      </script>


      When admin submit form order status is updated in database and also event eve is emitted. This event is used to pass id of order to status-changed compoennt. This component is placed in user panel and contains notification that order status has been changed.



      ///status changed component

      <template>
      <div v-if="sn" class="notification is-primary">
      <button class="delete" v-on:click="del()"></button>
      Staus of order nr {{nr}} has been changed
      </div>
      </template>

      <script>
      export default {
      created() {
      this.$root.$on("eve", data => {
      this.nr = data;
      });
      Echo.private("order" + this.nr).listen("status_changed", e => {
      this.sn = true;
      });
      },
      props: ,

      data: function() {
      return {
      sn: false,
      nr: 0
      };
      },
      methods: {
      del: function() {
      this.sn = false;
      }
      }
      };
      </script>


      Here is the problem. Variable nr is 0 all time. It'not changing dynamically. When nr is static or channel is public this code works fine. Please help.







      laravel vue.js pusher laravel-broadcast






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 25 '18 at 9:09









      appsonappson

      617




      617
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Put the Echo inside the $on. Otherwise the asynchronous $on happens too late to change nr in the Echo.



            created() {
          this.$root.$on("eve", data => {
          this.nr = data;
          Echo.private("order" + this.nr).listen("status_changed", e => {
          this.sn = true;
          });
          });
          }





          share|improve this answer
























          • Yes good one @Roy J. It has an asynchronous environment, hence the execution of the code will not guarantee to be sequential. So by putting the Echo instance inside the $on callback, it will be retrieve the id that you emitted, @appson.

            – Adis
            Nov 25 '18 at 14:09













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466073%2fhow-to-create-private-channel-name-dynamically%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Put the Echo inside the $on. Otherwise the asynchronous $on happens too late to change nr in the Echo.



            created() {
          this.$root.$on("eve", data => {
          this.nr = data;
          Echo.private("order" + this.nr).listen("status_changed", e => {
          this.sn = true;
          });
          });
          }





          share|improve this answer
























          • Yes good one @Roy J. It has an asynchronous environment, hence the execution of the code will not guarantee to be sequential. So by putting the Echo instance inside the $on callback, it will be retrieve the id that you emitted, @appson.

            – Adis
            Nov 25 '18 at 14:09


















          1














          Put the Echo inside the $on. Otherwise the asynchronous $on happens too late to change nr in the Echo.



            created() {
          this.$root.$on("eve", data => {
          this.nr = data;
          Echo.private("order" + this.nr).listen("status_changed", e => {
          this.sn = true;
          });
          });
          }





          share|improve this answer
























          • Yes good one @Roy J. It has an asynchronous environment, hence the execution of the code will not guarantee to be sequential. So by putting the Echo instance inside the $on callback, it will be retrieve the id that you emitted, @appson.

            – Adis
            Nov 25 '18 at 14:09
















          1












          1








          1







          Put the Echo inside the $on. Otherwise the asynchronous $on happens too late to change nr in the Echo.



            created() {
          this.$root.$on("eve", data => {
          this.nr = data;
          Echo.private("order" + this.nr).listen("status_changed", e => {
          this.sn = true;
          });
          });
          }





          share|improve this answer













          Put the Echo inside the $on. Otherwise the asynchronous $on happens too late to change nr in the Echo.



            created() {
          this.$root.$on("eve", data => {
          this.nr = data;
          Echo.private("order" + this.nr).listen("status_changed", e => {
          this.sn = true;
          });
          });
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 12:22









          Roy JRoy J

          26.4k33158




          26.4k33158













          • Yes good one @Roy J. It has an asynchronous environment, hence the execution of the code will not guarantee to be sequential. So by putting the Echo instance inside the $on callback, it will be retrieve the id that you emitted, @appson.

            – Adis
            Nov 25 '18 at 14:09





















          • Yes good one @Roy J. It has an asynchronous environment, hence the execution of the code will not guarantee to be sequential. So by putting the Echo instance inside the $on callback, it will be retrieve the id that you emitted, @appson.

            – Adis
            Nov 25 '18 at 14:09



















          Yes good one @Roy J. It has an asynchronous environment, hence the execution of the code will not guarantee to be sequential. So by putting the Echo instance inside the $on callback, it will be retrieve the id that you emitted, @appson.

          – Adis
          Nov 25 '18 at 14:09







          Yes good one @Roy J. It has an asynchronous environment, hence the execution of the code will not guarantee to be sequential. So by putting the Echo instance inside the $on callback, it will be retrieve the id that you emitted, @appson.

          – Adis
          Nov 25 '18 at 14:09




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466073%2fhow-to-create-private-channel-name-dynamically%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Unable to find Lightning Node

          Futebolista