Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mvnobrega's avatar

Ordering doesn't work in vuejs

I have the following account on my controller:

$todos_anos = $company->results()->distinct()->orderBy('ano', 'DESC')->select('ano')->get()->groupBy('ano');

If I do a dd(); I get exactly the expected result, which is my YEAR column with the data reversed.

Then I pass this variable to my vuejs component:

<ricentral :todos_anos="{{ $todos_anos }}"></ricentral>

and I loop through the data to display:

<option v-for="todo_ano in todos_anos" :value="todo_ano[0].ano">{{todo_ano[0].ano}}</option>


props: ['todos_anos'],
        data () {
          return {
            todos_anos: this.todos_anos
          }
        },

however, it does not appear ordered, it ignores the order in which I passed the data. I've already tried using reverse() , but it doesn't work either. Why is this behavior occurring? If I'm passing the data in a certain order to Vuejs, why is it ignoring it?

0 likes
2 replies
Ben Taylor's avatar

I don't know if this will help but I notice a couple of problems. First, your are not using a key for your looped options. You should probably add one.

Second, your data property is called the same thing as your prop. Don't do that. Give it a different name or just leave it as a prop

1 like

Please or to participate in this conversation.