how can i make pagination with limiter and range.. or ellipsis in Laravel Vue js?

Hello guys am using Laravel Vue Pagination in my table but the pargination has no limiter or ellipsis, when the data growing it out runs the table. how can i make a custom limiter and range / ellipsis

Like: < | 1 | 2 | 3 | … | 20 | 22 | >

This is how it looks now
This is how it show on the table pargination

This is my pagination code in vuejs

<div class="card-footer">
    <pagination :data="laptops" @pagination-change-page="getResults">
         <span slot="prev-nav">&lt; Previous</span>
         <span slot="next-nav">Next &gt;</span>
    </pagination>
</div>

This is my Script

getResults(page = 1){
   axios.get('/api/laptop?page=' + page)
   .then(response => {
   this.laptops = response.data;
   })
},

This is the controller

public function index()
    {
        return ViewDevices::where('Type','Laptop')->latest() -> paginate(15);
    }

SyntaxError: Unexpected token P in JSON at position 0

I am no able to undestand why it is not running.I have made similiar fetch requests and they were perfectly running but this one is showing this error

  const bookAdd = (userInfo, userPaymentInfo, NoOfDaysToStay, selectedRooms, Price, method, setUserInfo, setUserPaymentInfo, setNoOfDaysToStay, setSelectedRooms, setMethod) => {
    return (dispatch) => {
        let bookingDetails = { ...userInfo, ...userPaymentInfo, NoOfDaysToStay, selectedRooms, Price, method }
        fetch("http://localhost:5000/api/bookAdd", {

            method: "POST",

            body: JSON.stringify(bookingDetails),
            headers: {
                "Accept": "application/json",
                "Content-type": "application/json; charset=UTF-8"
            }
        })
            .then(function (response) {
                return response.json();
            })
            .then(function (data) {

                alert(data.message)
                if (data.success === true) {

                    setNoOfDaysToStay("")
                    setSelectedRooms("")
                    setMethod("cash")
                    setUserInfo({
                        Name: "",
                        ContactNo: "",
                        CNIC: "",
                        Address: "",
                        No0fPerson: "",
                        Email: ""
                    })
                    setUserPaymentInfo({
                        bankName: "",
                        cardNo: "",
                        cardCode: "",
                        expiryDate: ""
                    })
                }
            })
            .catch((error) => {
                console.log(error)
            })

    }
}
export { bookAdd }

JavaScript Reflection?

Say I want to use one function to ‘decorate’ another with input/output. But I want this wrapping to be optional, and if used, the function wrap ‘shadows’ the variable within the closure.

I have an object called customSettings that contains lambda functions that can be called, and also uses the variable ‘green’ within.

In ‘wrap’ I try to override the green variable value. Can I avoid hardcoding the variable name ‘green’ in ‘wrap’?

Eventually I’m thinking ‘wrap’ will be the generalized function, and the user uses it to define wrappingFunc, where for example the anonymous function ‘(g)=>’ returns an object. Then for each value that exists inside the object structure (eg. obj[‘greens’]), it overrides variable’s value within the context of the closure of the function specified.

Is this sort of variable name overriding possible in JavaScript? If not any pointers to this scenario?

    let greens = 100;
    // Defined object structure with specified keyword 'color' to be called by another function
    let customSettings: DrawSettingLambdas = new DrawSettingLambdas(GlobalDrawSetting, {
      color: () => {
        // Issue is here: I want to wrap this lambda object eventually with 'wrap', but I don't want to let the variable name 'greens' be hardcoded. Now I can hardcode a 'common' variable contextObj but then I can't use it for normal use cases now.
        // If i use 'greens', I'll have to write greens in the function below.
        //greens
        return ColorConversions.rgbToHex(0, contextObj['green'], 0);
      }
    });


    // Quick wrap
    function wrap(lambda, contextLambda) {
      return (inputLambda) => {
        // Variable name contextObj is hardcoded.
        let contextObj = {"green": contextLambda(inputLambda)};
        lambda();
      }
    }
    
    // eg. greens 1, 2, 3 returns the correct context numbers....
    let wrappingFunc = wrap(customSettings, (g)=>{return g * 100;});
    
    // Use wrap
    draw.AddGraph(subtractResults3, canvasRectangle3, [], wrappingFunc(1));
    draw.AddGraph(subtractResults2, canvasRectangle3, [], wrappingFunc(2));
    draw.AddGraph(subtractResults1, canvasRectangle3, [], wrappingFunc(3));

Using REST API for a Discord bot

I am trying to make my own discord bot (in discord.js v13). I found the official discord.js guide on this topic (https://discordjs.guide/additional-info/rest-api.html#making-http-requests-with-node and their example code is here: https://github.com/discordjs/guide/blob/main/code-samples/additional-info/rest-api/13/index.js) and I am trying to use/reuse the code from there to build my own bot.

The idea is to take a user input after the slash command “item” (so /item: firebrand), pass that user input into the URL (which allows you to get the information about that item from the backend/API) and use the response that is received to populate the various fields of an embed, which are sent back to the user. I am able to pass the user input and add it to the URL, which returns a usuable link, but the code breaks before the embed can be created. I put in a few console.log commands into my code to see where things are breaking.

(see location of console.log in the code below)

  • Console log 1: {“items”:[{“id”:14,”name”:”Frost Brand”,”type”:”1-h wpn”,”constlevel”:4,”mainlevel”:1,”mpath”:”W1″,”gemcost”:”5W”,”screenshot”:”/items/14/screenshot”}],”similarity”:-0}
  • Console log 2: https://dom5api.illwiki.com/items?match=fuzzy&name=frostbrand
  • Console log 3: [object Object]
  • Console log 4: [object Object]
  • Console log 5: undefined – TypeError: Cannot read properties of undefined (reading ‘length’)

My guess is that I am getting the TypeError because { list } is undefined. That is probably because itemSearchResult.body is giving back [object Object] as a response, but I have no clue how to fix that.

const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');
const { request } = require('undici');
const { ITEM_URL, BASE_URL } = require('../utils/utils');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('item')
        .setDescription('Replies with information about an item')
        .addStringOption(option => option.setName('item_name').setDescription('Enter the name of the item')),

    async execute(interaction) {
        
        
        async function getJSONResponse(body) {
            let fullBody = '';
            for await (const data of body) {
                fullBody += data.toString();
                console.log(`Console log 1: `+fullBody);
            }
            return JSON.parse(fullBody);
        }
        const itemName = interaction.options.getString('item_name');
        
        const itemSearchResult = await request(ITEM_URL + encodeURIComponent(itemName));
        console.log(`Console log 2: `+ITEM_URL + encodeURIComponent(itemName)); 
        console.log(`Console log 3: `+itemSearchResult.body);
        console.log(`Console log 4: `+itemSearchResult.body.toString())
        const { list } = await getJSONResponse(itemSearchResult.body);
        console.log(`Console log 5: `+list)

        if (!list.length) {
            await interaction.reply(`No results found for **${itemName}**.`);
        }

        const [answer] = list;
        
        const itemEmbed = new MessageEmbed()
            .setColor('#000000')
            .setTitle(answer.name)
            .setURL('X')
            .setAuthor({ name: 'Author' })
            .setDescription('Lot of hassle, but hey, it was working!')
            .setImage(BASE_URL + answer.screenshot)
            .setTimestamp()
            .setFooter({ text: 'A small step for X, a giant leap for X' });
        await interaction.reply({ embeds: [itemEmbed] });
    },
};

I tried searching for the error message/similar cases online and on StackOverflow, but found nothing. Any help is greatly appreciated!

How to wait for x seconds before clicking the next button using Javascript

I have this code that clicks on the elements. The purpose of these buttons is to open accordions. It works but I need to modify it a little bit so as to reduce the load on the server. At the moment, all the buttons are clicked at once which causes some buttons on the same page not to work.

I was wondering if there is a way to wait for at least 3 seconds before clicking on the next button. All the buttons share the same class name.

const matchBtns = document.querySelectorAll('.classname')
matchBtns.forEach(matchbtn => matchbtn.click())

I have tried to wrap the forEach inside the setTimeout but I can’t get it to work.

I tried

setTimeout(function() { matchBtns.forEach(matchbtn => matchbtn.click());}, 3000);

Thanks

Cancel the entered data in the calendar

At the moment, there is a calendar on my site where the user can select a time range and data filtering will be done. For this I use the react-advanced-datetimerange-picker library.

But there is one drawback. You cannot cancel the selected data without reloading the page.
Please tell me how to make a button (example near close button) that will allow you to reset the entered filters and get the entire list of data again.

Here I have given a simplified example of my code

https://codesandbox.io/s/admiring-currying-32gvd2

Svelte: Data flow between components – how to pass state of children to parent(s)

I haven’t been using svelte for very long but I can see a couple ways to go about doing what I need, but they are all feel “un-svelte”, so I’m hoping there’s a more obvious solution I’m missing. Here is the layout code before I go on about what I need it to do.

        <ControlGroup>
            <ControlLabel label='Language'>
                <Select options={lang_options} on:select={(e) => $settings.lang = e.detail} />
            </ControlLabel>
            <ControlLabel label='Visibility'>
                <Select options={...} on:select />
                <Select options={...} on:select />
            </ControlLabel>
            <ControlLabel label='Some other setting'>
                <Select options={...} on:select />
                <Select options={...} on:select />
            </ControlLabel>
        </ControlGroup>

First, the deepest nested elements (selects), need to update one or many stores. So far so good, the on:select directive makes quick work of that.

Second, the selects all have a defaultoption, which if none is provided will be options[0]. The <ControlGroup> needs to be aware if the selects within itself are default. Because when they aren’t, a button to reset the selects should be visible, and clicking that should run the reset() function in the selects.

More broadly, the <ControlGroup> and <ControlLabel> components are there to structure the layout, they don’t have any complicated logic. They use svelte slots to pass down components. Worth noting, I wrote the multiselects so it’s not an opaque library and I can add stuff to them if that’s part of the solution.

So without having a reactive let for every single control and then passing lists of those to the controlgroups, what can I do?

Thank you !

React not loading my images. I know this is a popular question

Okay guys, please don’t bash me. I’m new here and I know this has been asked a bunch. I’ve spent an hour researching and trying before I came here to post.

So I have a file called Intro.jsx and I am trying to add the GitHub logo which is in a folder called ‘imp’ which is inside my ‘src’ folder but outside my ‘components’ folder.

I have tried moving the img folder around to other locations but still have the same error

now I have tried the following:

import Github from '../../img/github.png'

import Github from '../img/github.png'

import Github from './img/github.png'

import Github from '../src/img/github.png'

I’ve even tried some other ones too. I can’t get it to load. My error is nearly the same every time.

const Intro = () => {
    return (
        <div className="intro">
            <div className="i-left">
                <div className="i-name">
                    <span>I am </span>
                    <span>Josh!</span>
                    <span>
                        Lorem ipsum dolor sit amet consectetur adipisicing elit. Ex,
                        doloribus? Explicabo, itaque? Sit adipisci odio mollitia veritatis
                        hic laudantium quisquam itaque ad
                    </span>
                </div>
                <button className="i-button button">Hire Me</button>
                <div className="i-icons">
                    <img src="{Github}" alt="" />
                    <img src="{LinkedIn}" alt="" />
                    <img src="{Instagram}" alt="" />
                </div>
            </div>
            <div className="i-right">I am right side</div>
        </div>
    );
};

Current Error:

ERROR in ./src/components/Intro/Intro.jsx 6:0-39

Module not found: Error: Can't resolve '../img/github.png' in '/Users/josh/Desktop/my-portfolio/src/components/Intro'

How can I fix this? and what am I doing wrong? Thank you for your patience and help!

I tried to upload an image but can not because I am new here

Multi steps Dropbox logic in React JS

I hope you and your families are well.
I need your guidance on a small issue which I am facing, I have been trying to find/do the solution for the past 3 days and couldn’t find it.

I am using a simple React library for the below.

Scenario
I have created 4 dropboxes,

  1. IDdropbox = it contains, some numbers, and this id is enabled when the webapp load, and rest all are disabled. When anyone clicked and choose ID, it enable the second dropdown menu FruitList
  2. Fruitlist – the options here are populated depending on the ID chosen before, and enable the thirst dropdown menu
  3. extraFlavor = it will contain some extra flavour option, and this list is populated by the previous option (FruitList)
  4. recepieMenu = it enable by previous action, and it shows the options set my extra flavour

Working
For example

  1. If user selected 2 in the first dropdown
  2. then the second dropdown should show “Orange, Banana, Apple”
  3. If use choose Orange, then the third dropdown should show “Vanilla”,”strawberry” etc
  4. One user select Vanilla, then the 4th dropdown should show something like “Valline Apple Shake, “Vanilla Apple Ice Cream” etc

Issue
Now the issue is, I can use Dropdown1, that’ is not an issue, but I am not able to populate data in the rest of the dropdowns. I tried using ReactHooks, userState, useEffect, and they are not working for me.

I know, I might be doing something stupid, but I couldn’t find out where is issue lies.

Thanks for reading this question and thanks for your time.

Regards
Aman

Choose the fruis

import React, { useState, useRef, useEffect } from “react”;
const ChooseTheFruit = () => {

function CreateOptions(props) {
    let data = Array.from(props.data)
    return (data.map((item, index) => <option key={index} >{item}</option>)
    )
}

const [idNumber, setIdNumber] = useState([1, 2, 3, 4, 5]);
const [fruitList, setFruitList] = useState([]);

useEffect(() => {

    setFruitList(fruitList)
}, [fruitList])

//functions
const populateFruits = (e) => {
    const currentID = e.target.value
    console.log(currentID);
    setIdNumber(currentID);

    switch (currentID) {

        case 1:
            setFruitList("Orange,Pineapple");
            break;
        case 2:
            setFruitList("Kiwi,Banana");
            break;
        case 3:
            setFruitList("Almonda,Pistachu");
            break;
        case 4:
            setFruitList("Papaya,Mango");
            break;
        case 5:
            setFruitList("Muskmelon,Watermalon");
            break;
        default:
            break;
    }

    console.log(fruitList)

}

//rendering
return (
    <>
        <div>
            <h3>Please choose the Fruit</h3>
            <br />
            <select id={"myNumber"}
                onChange={populateFruits}
            >
                <CreateOptions data={idNumber} />
            </select>
            <br />
            <select id={"fruitList"} > <CreateOptions data={fruitList} /></select>
            <br />
            <select id={"extraFavourMenu"} ></select>
            <br />
            <select id={"recepieMenu"} ></select>
            <br />
            <button>Fetch Receipe</button>
        </div>
        <div id="receipe" >here we will show recepie contents</div>
    </>
);
}
export default ChooseTheFruit;

DateTime object to local string and then back to Date, confusing? [duplicate]

I need to compare dates somewhere for the datetime object so I am converting DateTime Object in js to local date string and then converting it back to datetime object.
It is working but in some particular cases the conversion back to datetime object gives Invalid date, don’t know why?

If someone can help me out with:

  1. why this is happening?
  2. How to achieve this, if this doesn’t work?

enter image description here

Javascript Array, search and create new Array;

From an array in Javascript how can I search it for specific values and return a new array with the index of the array and location.

In the example I wish to search the work array for the year 1990. If the year exists I want to create or add to a new array both the index from the work array and the location where it exists.

Potentially the length of the work array will be a lot bigger, otherwise I would have just used a loop over them to extract the information.

Thanks.

// Search work for the year 1990
  work  = [];
    work[0] = [1985, 1987, 1990, 2000, 2010];   // location 2
    work[1] = [1984, 1998];
    work[2] = [1975, 1986, 1987, 1990]; // location 3
    work[3] = [2001, 2010];                   
    work[4] = [1977, 1978, 1990] // location 2
    
  
    // would create and end up
    sorted[0]     = [0, 2]; // index and location from work;
    sorted[1]     = [2, 3];
    sorted[2]   = [4, 2];