[Vuejs]-How to show favorite project using pivot in vue and laravel

0👍

Define a computed property that filters your projects returning just the objects that have a true value for the favorite property.

I’m making some assumptions regarding the structure of your project object, however, the principle will remain the same.

An example of how you could filter results below:

let projects = [
    {
    id: 1,
    favorite: true
  },
  {
    id: 2,
    favorite: false
  },
  {
    id: 3,
    favorite: false
  },
  {
    id: 4,
    favorite: true
  }
];

let filteredProjects = projects.filter(p => p.favorite);

Obviously, you’re not using a static array as I have in the example so you will need to alter it for your use case (e.g. state.projects.filter(p => p.favorite)). You could also use lodash filter if you’re already using that library.

Leave a comment