'Associative Array Use to get dynamics Cards index in Laravel Blade using php
I am a beginner in Larvavel and stuck at a point, need help. I am working on an e-commerce app, in which each product(i.e, a t-shirt) have multiple colors and each color has multiple sizes,
Users should be able to add products in this format
color[$i]size[$j]
which means For First Color Product:
color[0]size[0]
color[0]size[1]
For Second Product Color
color[1]size[0]
color[1]size[1]
color[1]size[2]
and similar for Multiple products as required
Add More Size button to add one more size to this color, and Add button to add new product color
Solution 1:[1]
When we want to "connect" differents elements, we can use a SVG.
First we can defined you data. I imagine toy has an array like
trips = [
{ text: 'BLR-MAA', level: 1 },
{ text: 'MAA-HYD', level: 1 },
{ text: 'BLR-HYD', level: 1 },
{ text: 'HYB-DEL', level: 0 },
{ text: 'HYB-DEL', level: 0 },
{ text: 'DEL-BLR', level: 1 },
];
I number the levels from top (0 the most upper) to bottom
You can has, then
<div #wrapper class="wrapper">
<ng-container *ngFor="let trip of trips; let i = index">
<div
#airport
class="airport"
[style.padding-top.px]="trip.level * 50"
>
{{ trip.text }}
</div>
</ng-container>
</div>
Where
.wrapper{
display:flex;
justify-content:space-between;
flex-wrap: nowrap;
min-height: 68px;
}
.wrapper::after{
content:' '
}
.airport
{
width:80px;
text-align: center;
}
To draw the svg we need create a series of "path". This paths need know the with of the elements and the widht of the wrapper this is the reason we need
@ViewChild('wrapper') wrapper:ElementRef
@ViewChild('airport') airport:ElementRef
The "funny" is create the function that return an array of paths
getPaths()
{
const rect=this.wrapper.nativeElement.getBoundingClientRect();
let width=this.airport.nativeElement.getBoundingClientRect().width
const space=(rect.width-width*this.trips.length)/(this.trips.length)
width=width+space
const paths = [];
this.trips.forEach((trip, i) => {
if (i) {
const fromY = this.trips[i - 1].level * 50+1; //add 1 to to allow showed the line
const fromX = i * width - space;
const toY = trip.level * 50+1; //add 1 to allow showed the line
const toX = i *width;
if (trip.level == this.trips[i - 1].level) {
paths.push(
'M' + fromX + ',' + fromY + ' L' + (toX) + ',' + toY
);
} else {
const middle=(fromX+toX)/2)
paths.push(
'M' + fromX + ',' + fromY + ' C' + middle + ',' + fromY+
' '+middle+','+toY+' '+toX+','+toY
);
}
}
});
return paths;
}
}
See that is two adjacents elements are in the same level we create a line (we use M to move to the origin and L to draw the line
If two adjacents elements are in a different level we create a curve (we use M to move to the origin and C to create the curve)
The last in create the svg enclosed in a div with position absolute and all in a div with position relative
<div style="position:relative">
<div #wrapper class="wrapper">
...
</div>
<div style="position:absolute;top:.5rem">
<svg stroke="red" fill="transparent" [attr.width]="wrapper.offsetWidth"
[attr.heigth]="wrapper.offsetHeight" >
<path *ngFor="let path of paths" [attr.d]="path" />
</svg>
</div>
</div>
See how we give the same width and heigth to our svg using the template reference variable "wrapper" and offsetHeigth/offsetWidth
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
