M
M
MiJuniorDev2019-12-27 23:34:38
Laravel
MiJuniorDev, 2019-12-27 23:34:38

What is the best way to pass large collections of data from Laravel to Vue.js?

For example, there are 8k users, how best to transfer them to the view, I tried it as props, but it just doesn’t work, it says that the collection is empty, I suspect that it doesn’t have time to process the props.
Is it better to get a query on the apishka when the view is created?
What other options are there?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2019-12-27
@MiJuniorDev

pagination. dumping all users at once does not make sense.

S
Sergey Sokolov, 2019-12-27
@sergiks

You can create a global variable or function in the page code that will return an array of users.
users/show.blade.php

<script>
  function getMyUsers() { return @json($arrayOfUsers); }
</script>
...
<script>
const vm = new Vue({
  data: function() {
    return {
      users: getMyUsers(),
      counter: 0,
    };
  }
});

And this way you can pack not all, but, for example, only the first 500 users.
And if they start scrolling / scrolling, then dynamically, add. requests, load further.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question