Skip to main content

How to show products based on each category in Laravel and JavaScript

I have Categories in my Database and The products that should be displayed once I click the buttons of each category so here is my items blade code :

@foreach ($categories as $category)
<span id="span-" class="item"  data-name=""  onclick="btnClick(this)"></span>
 @endforeach

<div  class="activities-grid">
          @foreach ($products as $product)
        <div id="test1" class="activities-grid-item " style=" background-image: url(/">
          <h1 class="activities-h1">
    TEST1
          </h1>
        <div class="col-md-3 col-sm-6 my-3 my-md-0">
         <div class="card-body">
              <h6 class="icons">
                  <i class="fas fa-star"></i>
                  <i class="fas fa-star"></i>
                  <i class="fas fa-star"></i>
                  <i class="fas fa-star"></i>
                  <i class="far fa-star"></i>
              </h6>

          </div>

         </div>

                       <div class="card-stuff">

                    <p class="card-text"></p>
                    <span class="price"></span>
                    ?>
                </div>
        </div>
        @endforeach

(I did the same code for every product)

and this is my JavaScript code :


function btnClick(btn){
  const name = btn.getAttribute('data-name');
  const span1 = document.getElementById("span-test1");
  const span2 = document.getElementById("span-test2");
  const span3 = document.getElementById("span-test3");
  const span4 = document.getElementById("span-test4");
  const span5 = document.getElementById("span-test5");
  const span6 = document.getElementById("span-test6");
  const test1 = document.querySelectorAll('#test1');
  const test2= document.querySelectorAll('#test2');
  const test3= document.querySelectorAll('#test3');
  const test4= document.querySelectorAll('#test4');
  const test5= document.querySelectorAll('#test5');
  const test6= document.querySelectorAll('#test6');
  switch(name){
      case 'test1':
        span1.classList.add('active');
        span2.classList.remove('active');
        span3.classList.remove('active');
        span4.classList.remove('active');
        span5.classList.remove('active');
        span6.classList.remove('active');
        for (i = 0; i < test1.length; i++) {
          test1[i].style.display = "flex";
        }
        for (i = 0; i < test2.length; i++) {
          test2[i].style.display = "none";
        }
        for (i = 0; i < test3.length; i++) {
          test3[i].style.display = "none";
        }
        for (i = 0; i < test4.length; i++) {
          test4[i].style.display = "none";
        }
        for (i = 0; i < test5.length; i++) {
          test5[i].style.display = "none";
        }
        for (i = 0; i < test6.length; i++) {
          test6[i].style.display = "none";
        }
          break;

(I did the same code for every case)

So Please any idea how to fix this problem and display every product based in it category?



source https://stackoverflow.com/questions/68958051/how-to-show-products-based-on-each-category-in-laravel-and-javascript

Comments

Popular posts from this blog

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

The number of nodes and edges I calculated manually and by a method provided by networkx library dont match

I am trying to analyse a graph using networkx library in Python. I have implemented a function that returns the nodes and edges of that graph. After that I counted the number of nodes and edges by implementing the len() function for nodes and edges, which gave me 17 for both nodes and edges. However, when I used the method graph.number_of_nodes() of networkx library it gave me 53. My code: import pandas as pd import networkx as nx import matplotlib.pyplot as plt header_list = ["a","b","w"] E =pd.read_csv("aves-barn-swallow-contact-network.edges",sep=" ",header= None,names=header_list) # print(E.head()) # prints first few rows of the csv file G = nx.from_pandas_edgelist(E,"a","b",["w"]) nx.draw(G) plt.show() class GraphAnalyse: #finding nodes and edges def nodeEdge(self,Graph): nodes = Graph.nodes() edges = Graph.edges() ...