how can i filter data which only have desired width on data like this in laravel 8

Viewed 61

i want to combine the data and display it based on the width value of each item, with a table like this how can i do that

 my controller
public function test(){

    // $item = '20/20/20';
    // $dimension = 'width/height/depth';
    $item = TestItem::join('t_dimensions','t_items.dimension_id', '=', 't_dimensions.id')->get();

    //foreach($item as $item){
        //$size = explode('/',$item->size);
        //$item = explode('/',$item->dimension);
    //}

    return response->json($item);
}

table dimensions

id dimension
1 Height/Width
2 Width/Height/Depth

table items

id item size dimension_id
1 mistar 20/5 1
2 board 50/100 1
3 board 80/50 1
4 pipe 120/50/80 2
5 plate 200/100 1

i want to display data like this, only display data that has width >= 100

  1. board Height 50, Width 100
  1. pipe Width 100,Height 50, Depth 80
  1. plate Width 200, Height 100
1 Answers

I hope this will help you, apply the logic in blade file in foreach loop

 @foreach ($items as $product )
@Php
  [$width,$height,$depth] = explode("/",$product->size);
@endphp
@if ($width >= 100)
 <li>ID: {{ $product->item }}, Width {{ $width}} , depth {{$depth}}</li>
@endif

@endforeach

Related